Repository: cassandra Updated Branches: refs/heads/trunk 03f5997f9 -> 1db54a126
Fix cassandra-stress startup failure patch by Jay Zhuang; reviewed by Blake Eggleston for CASSANDRA-14106 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/1db54a12 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/1db54a12 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/1db54a12 Branch: refs/heads/trunk Commit: 1db54a1266a68d9c765c0fa248277635c4520f6d Parents: 03f5997 Author: Jay Zhuang <jay.zhu...@yahoo.com> Authored: Mon Dec 11 23:11:21 2017 -0800 Committer: Blake Eggleston <bdeggles...@gmail.com> Committed: Tue Dec 19 16:23:07 2017 -0800 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/stress/generate/Distribution.java | 4 +- .../generate/DistributionGaussianTest.java | 77 ++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/1db54a12/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index ee436e6..15954c8 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0 + * Fix cassandra-stress startup failure (CASSANDRA-14106) * Remove initialDirectories from CFS (CASSANDRA-13928) * Fix trivial log format error (CASSANDRA-14015) * Allow sstabledump to do a json object per partition (CASSANDRA-13848) http://git-wip-us.apache.org/repos/asf/cassandra/blob/1db54a12/tools/stress/src/org/apache/cassandra/stress/generate/Distribution.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/Distribution.java b/tools/stress/src/org/apache/cassandra/stress/generate/Distribution.java index 30efd34..9d8ce1c 100644 --- a/tools/stress/src/org/apache/cassandra/stress/generate/Distribution.java +++ b/tools/stress/src/org/apache/cassandra/stress/generate/Distribution.java @@ -45,8 +45,8 @@ public abstract class Distribution implements Serializable public long average() { double sum = 0; - double d = 0d; - for (int count = 0; count < 50 ; count++) + float d = 0; + for (int count = 0; count < 51 ; count++) { sum += inverseCumProb(d); d += 0.02d; http://git-wip-us.apache.org/repos/asf/cassandra/blob/1db54a12/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionGaussianTest.java ---------------------------------------------------------------------- diff --git a/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionGaussianTest.java b/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionGaussianTest.java new file mode 100644 index 0000000..7f262e9 --- /dev/null +++ b/tools/stress/test/unit/org/apache/cassandra/stress/generate/DistributionGaussianTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.stress.generate; + +import org.junit.Test; + +import org.apache.cassandra.stress.settings.OptionDistribution; + +import static java.lang.Math.toIntExact; +import static org.junit.Assert.*; + +public class DistributionGaussianTest +{ + @Test + public void simpleGaussian() + { + Distribution dist = OptionDistribution.get("gaussian(1..10)").get(); + assertTrue(dist instanceof DistributionBoundApache); + + assertEquals(1, dist.minValue()); + assertEquals(10, dist.maxValue()); + assertEquals(5, dist.average()); + + assertEquals(1, dist.inverseCumProb(0d)); + assertEquals(10, dist.inverseCumProb(1d)); + + int testCount = 100000; + int[] results = new int[11]; + for (int i = 0; i < testCount; i++) + { + int val = toIntExact(dist.next()); + results[val]++; + } + + // Increasing for the first half + for (int i = toIntExact(dist.minValue()); i < dist.average(); i++) + { + assertTrue(results[i] < results[i + 1]); + } + + // Decreasing for the second half + for (int i = toIntExact(dist.average()) + 1; i < dist.maxValue(); i++) + { + assertTrue(results[i] > results[i + 1]); + } + } + + @Test + public void negValueGaussian() + { + Distribution dist = OptionDistribution.get("gaussian(-1000..-10)").get(); + assertTrue(dist instanceof DistributionBoundApache); + + assertEquals(-1000, dist.minValue()); + assertEquals( -10, dist.maxValue()); + assertEquals(-504, dist.average()); + + assertEquals(-1000, dist.inverseCumProb(0d)); + assertEquals(-10, dist.inverseCumProb(1d)); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org