diff --git a/tools/cqlstress-counter-example.yaml b/tools/cqlstress-counter-example.yaml index 9084e84358..2430e504d8 100644 --- a/tools/cqlstress-counter-example.yaml +++ b/tools/cqlstress-counter-example.yaml @@ -48,11 +48,10 @@ table_definition: | # 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] # 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 # # If preceded by ~, the distribution is inverted -# # Defaults for all columns are size: uniform(4..8), population: uniform(1..100B), cluster: fixed(1) # diff --git a/tools/cqlstress-example.yaml b/tools/cqlstress-example.yaml index b2b915de30..cde345a575 100644 --- a/tools/cqlstress-example.yaml +++ b/tools/cqlstress-example.yaml @@ -59,7 +59,7 @@ table_definition: | # 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] # 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 # # If preceded by ~, the distribution is inverted diff --git a/tools/cqlstress-insanity-example.yaml b/tools/cqlstress-insanity-example.yaml index 35bcd4a0fc..5eb4feca84 100644 --- a/tools/cqlstress-insanity-example.yaml +++ b/tools/cqlstress-insanity-example.yaml @@ -58,7 +58,7 @@ table_definition: | # 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] # 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 # # If preceded by ~, the distribution is inverted diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/DistributionSequence.java b/tools/stress/src/org/apache/cassandra/stress/generate/DistributionSequence.java index 424c6611fd..0546897100 100644 --- a/tools/stress/src/org/apache/cassandra/stress/generate/DistributionSequence.java +++ b/tools/stress/src/org/apache/cassandra/stress/generate/DistributionSequence.java @@ -63,7 +63,10 @@ public class DistributionSequence extends Distribution } @Override - public void setSeed(long seed){} + public void setSeed(long seed) + { + next.set(seed); + } } diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/OptionDistribution.java b/tools/stress/src/org/apache/cassandra/stress/settings/OptionDistribution.java index 8784158c3c..cc93323c88 100644 --- a/tools/stress/src/org/apache/cassandra/stress/settings/OptionDistribution.java +++ b/tools/stress/src/org/apache/cassandra/stress/settings/OptionDistribution.java @@ -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("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("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", "Aliases: extr, qextr, gauss, normal, norm, weibull" ); diff --git a/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionSequenceTest.java b/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionSequenceTest.java index 6f184d7643..591833c9d0 100644 --- a/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionSequenceTest.java +++ b/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionSequenceTest.java @@ -96,4 +96,35 @@ public class DistributionSequenceTest 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; + } + } + } }