mirror of https://github.com/apache/cassandra
Add sequence distribution type to cassandra stress: fix problem with setSeed()
Patch by Ben Slater; reviewed by Stefania Alborghetti for CASSANDRA-12490
This commit is contained in:
parent
d4a914d216
commit
7c759e2c32
|
|
@ -48,11 +48,10 @@ table_definition: |
|
||||||
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
|
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
|
||||||
# UNIFORM(min..max) A uniform distribution over the range [min, max]
|
# UNIFORM(min..max) A uniform distribution over the range [min, max]
|
||||||
# FIXED(val) A fixed distribution, always returning the same value
|
# FIXED(val) A fixed distribution, always returning the same value
|
||||||
# SEQ(min..max) A fixed sequence, returning values from min to max sequentially, wrapping if necessary.
|
# SEQ(min..max) A fixed sequence, returning values in the range min to max sequentially (starting based on seed), wrapping if necessary.
|
||||||
# Aliases: extr, gauss, normal, norm, weibull
|
# Aliases: extr, gauss, normal, norm, weibull
|
||||||
#
|
#
|
||||||
# If preceded by ~, the distribution is inverted
|
# If preceded by ~, the distribution is inverted
|
||||||
#
|
|
||||||
# Defaults for all columns are size: uniform(4..8), population: uniform(1..100B), cluster: fixed(1)
|
# Defaults for all columns are size: uniform(4..8), population: uniform(1..100B), cluster: fixed(1)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ table_definition: |
|
||||||
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
|
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
|
||||||
# UNIFORM(min..max) A uniform distribution over the range [min, max]
|
# UNIFORM(min..max) A uniform distribution over the range [min, max]
|
||||||
# FIXED(val) A fixed distribution, always returning the same value
|
# FIXED(val) A fixed distribution, always returning the same value
|
||||||
# SEQ(min..max) A fixed sequence, returning values from min to max sequentially, wrapping if necessary.
|
# SEQ(min..max) A fixed sequence, returning values in the range min to max sequentially (starting based on seed), wrapping if necessary.
|
||||||
# Aliases: extr, gauss, normal, norm, weibull
|
# Aliases: extr, gauss, normal, norm, weibull
|
||||||
#
|
#
|
||||||
# If preceded by ~, the distribution is inverted
|
# If preceded by ~, the distribution is inverted
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ table_definition: |
|
||||||
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
|
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
|
||||||
# UNIFORM(min..max) A uniform distribution over the range [min, max]
|
# UNIFORM(min..max) A uniform distribution over the range [min, max]
|
||||||
# FIXED(val) A fixed distribution, always returning the same value
|
# FIXED(val) A fixed distribution, always returning the same value
|
||||||
# SEQ(min..max) A fixed sequence, returning values from min to max sequentially, wrapping if necessary.
|
# SEQ(min..max) A fixed sequence, returning values in the range min to max sequentially (starting based on seed), wrapping if necessary.
|
||||||
# Aliases: extr, gauss, normal, norm, weibull
|
# Aliases: extr, gauss, normal, norm, weibull
|
||||||
#
|
#
|
||||||
# If preceded by ~, the distribution is inverted
|
# If preceded by ~, the distribution is inverted
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,10 @@ public class DistributionSequence extends Distribution
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSeed(long seed){}
|
public void setSeed(long seed)
|
||||||
|
{
|
||||||
|
next.set(seed);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ public class OptionDistribution extends Option
|
||||||
GroupedOptions.formatMultiLine("GAUSSIAN(min..max,mean,stdev)", "A gaussian/normal distribution, with explicitly defined mean and stdev"),
|
GroupedOptions.formatMultiLine("GAUSSIAN(min..max,mean,stdev)", "A gaussian/normal distribution, with explicitly defined mean and stdev"),
|
||||||
GroupedOptions.formatMultiLine("UNIFORM(min..max)", "A uniform distribution over the range [min, max]"),
|
GroupedOptions.formatMultiLine("UNIFORM(min..max)", "A uniform distribution over the range [min, max]"),
|
||||||
GroupedOptions.formatMultiLine("FIXED(val)", "A fixed distribution, always returning the same value"),
|
GroupedOptions.formatMultiLine("FIXED(val)", "A fixed distribution, always returning the same value"),
|
||||||
GroupedOptions.formatMultiLine("SEQ(min..max)", "A fixed sequence, returning values from min to max sequentially, wrapping if necessary."),
|
GroupedOptions.formatMultiLine("SEQ(min..max)", "A fixed sequence, returning values in the range min to max sequentially (starting based on seed), wrapping if necessary."),
|
||||||
"Preceding the name with ~ will invert the distribution, e.g. ~exp(1..10) will yield 10 most, instead of least, often",
|
"Preceding the name with ~ will invert the distribution, e.g. ~exp(1..10) will yield 10 most, instead of least, often",
|
||||||
"Aliases: extr, qextr, gauss, normal, norm, weibull"
|
"Aliases: extr, qextr, gauss, normal, norm, weibull"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -96,4 +96,35 @@ public class DistributionSequenceTest
|
||||||
assertEquals(Long.MAX_VALUE, dist.inverseCumProb(1d));
|
assertEquals(Long.MAX_VALUE, dist.inverseCumProb(1d));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setSeed() throws Exception
|
||||||
|
{
|
||||||
|
Distribution dist = OptionDistribution.get("seq(1..10)").get();
|
||||||
|
assertTrue(dist instanceof DistributionSequence);
|
||||||
|
|
||||||
|
for (int seed=1; seed<500; seed+=seed)
|
||||||
|
{
|
||||||
|
dist.setSeed(seed);
|
||||||
|
assertEquals(1, dist.minValue());
|
||||||
|
assertEquals(10, dist.maxValue());
|
||||||
|
assertEquals(5, dist.average());
|
||||||
|
|
||||||
|
assertEquals(1, dist.inverseCumProb(0d));
|
||||||
|
assertEquals(10, dist.inverseCumProb(1d));
|
||||||
|
|
||||||
|
long last = dist.next();
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
|
long next = dist.next();
|
||||||
|
if (next>1)
|
||||||
|
{
|
||||||
|
assertEquals(next, last + 1); //increase by one each step
|
||||||
|
}else{
|
||||||
|
assertEquals(last, 10); //wrap after the end
|
||||||
|
}
|
||||||
|
last = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue