cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r788771 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/gms/ test/unit/org/apache/cassandra/gms/ test/unit/org/apache/cassandra/utils/
Date Fri, 26 Jun 2009 17:22:41 GMT
Author: jbellis
Date: Fri Jun 26 17:22:40 2009
New Revision: 788771

URL: http://svn.apache.org/viewvc?rev=788771&view=rev
Log:
some gms tests.  patch by johano; reviewed by jbellis for CASSANDRA-249

Added:
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/GossipDigestTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/FailureDetector.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/FailureDetector.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/FailureDetector.java?rev=788771&r1=788770&r2=788771&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/FailureDetector.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/FailureDetector.java Fri Jun
26 17:22:40 2009
@@ -57,6 +57,8 @@
     /* The time when the module was instantiated. */
     private static long creationTime_;
     
+    private Gossiper gossiper;
+    
     public static IFailureDetector instance()
     {        
         if ( failureDetector_ == null )
@@ -66,7 +68,7 @@
             {
                 if ( failureDetector_ == null )
                 {
-                    failureDetector_ = new FailureDetector();
+                    failureDetector_ = new FailureDetector(Gossiper.instance());
                 }
             }
             finally
@@ -80,8 +82,9 @@
     private Map<EndPoint, ArrivalWindow> arrivalSamples_ = new Hashtable<EndPoint,
ArrivalWindow>();
     private List<IFailureDetectionEventListener> fdEvntListeners_ = new ArrayList<IFailureDetectionEventListener>();
     
-    public FailureDetector()
+    public FailureDetector(Gossiper gossiper)
     {
+        this.gossiper = gossiper;
         creationTime_ = System.currentTimeMillis();
         // Register this instance with JMX
         try
@@ -238,11 +241,9 @@
     private static Logger logger_ = Logger.getLogger(ArrivalWindow.class);
     private double tLast_ = 0L;
     private BoundedStatsDeque arrivalIntervals_;
-    private int size_;
     
     ArrivalWindow(int size)
     {
-        size_ = size;
         arrivalIntervals_ = new BoundedStatsDeque(size);
     }
     

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java?rev=788771&r1=788770&r2=788771&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java Fri Jun
26 17:22:40 2009
@@ -91,6 +91,7 @@
     {
         return version_;
     }
+    
 };
 
 class HeartBeatStateSerializer implements ICompactSerializer<HeartBeatState>

Added: incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java?rev=788771&view=auto
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java (added)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java Fri
Jun 26 17:22:40 2009
@@ -0,0 +1,29 @@
+package org.apache.cassandra.gms;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ArrivalWindowTest
+{
+    
+    @Test
+    public void test()
+    {
+        ArrivalWindow window = new ArrivalWindow(4);
+        //base readings
+        window.add(111);
+        window.add(222);
+        window.add(333);
+        window.add(444);
+        window.add(555);
+
+        //all good
+        assertEquals(0.4342, window.phi(666), 0.01);
+        
+        //oh noes, a much higher timestamp, something went wrong!
+        assertEquals(9.566, window.phi(3000), 0.01);
+    }
+
+
+}

Added: incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/GossipDigestTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/GossipDigestTest.java?rev=788771&view=auto
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/GossipDigestTest.java (added)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/gms/GossipDigestTest.java Fri
Jun 26 17:22:40 2009
@@ -0,0 +1,37 @@
+package org.apache.cassandra.gms;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.apache.cassandra.io.DataInputBuffer;
+import org.apache.cassandra.io.DataOutputBuffer;
+import org.apache.cassandra.net.EndPoint;
+import org.junit.Test;
+
+public class GossipDigestTest
+{
+
+    @Test
+    public void test() throws IOException
+    {
+        EndPoint endPoint = new EndPoint("127.0.0.1", 3333);
+        int generation = 0;
+        int maxVersion = 123;
+        GossipDigest expected = new GossipDigest(endPoint, generation, maxVersion);
+        //make sure we get the same values out
+        assertEquals(endPoint, expected.getEndPoint());
+        assertEquals(generation, expected.getGeneration());
+        assertEquals(maxVersion, expected.getMaxVersion());
+        
+        //test the serialization and equals
+        DataOutputBuffer output = new DataOutputBuffer();
+        GossipDigest.serializer().serialize(expected, output);
+        
+        DataInputBuffer input = new DataInputBuffer();
+        input.reset(output.getData(), output.getLength());
+        GossipDigest actual = GossipDigest.serializer().deserialize(input);
+        assertEquals(0, expected.compareTo(actual));
+    }
+
+}

Added: incubator/cassandra/trunk/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java?rev=788771&view=auto
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
(added)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
Fri Jun 26 17:22:40 2009
@@ -0,0 +1,57 @@
+package org.apache.cassandra.utils;
+
+import static org.junit.Assert.*;
+
+import java.util.Iterator;
+
+import org.junit.Test;
+
+public class BoundedStatsDequeTest
+{
+
+    @Test
+    public void test()
+    {
+        int size = 4;
+        
+        BoundedStatsDeque bsd = new BoundedStatsDeque(size);
+        //check the values for an empty result
+        assertEquals(0, bsd.size());
+        assertEquals(0, bsd.sum(), 0.001d);
+        assertEquals(Double.NaN, bsd.mean(), 0.001d);
+        assertEquals(Double.NaN, bsd.variance(), 0.001d);
+        assertEquals(Double.NaN, bsd.stdev(), 0.001d);
+        assertEquals(0, bsd.sumOfDeviations(), 0.001d);
+        
+        bsd.add(1d); //this one falls out, over limit
+        bsd.add(2d);
+        bsd.add(3d);
+        bsd.add(4d);
+        bsd.add(5d);
+        
+        //verify that everything is in there
+        Iterator<Double> iter = bsd.iterator();
+        assertTrue(iter.hasNext());
+        assertEquals(2d, iter.next(), 0);
+        assertTrue(iter.hasNext());
+        assertEquals(3d, iter.next(), 0);
+        assertTrue(iter.hasNext());
+        assertEquals(4d, iter.next(), 0);
+        assertTrue(iter.hasNext());
+        assertEquals(5d, iter.next(), 0);
+        assertFalse(iter.hasNext());
+        
+        //check results
+        assertEquals(size, bsd.size());
+        assertEquals(14, bsd.sum(), 0.001d);
+        assertEquals(3.5, bsd.mean(), 0.001d);
+        assertEquals(1.25, bsd.variance(), 0.001d);
+        assertEquals(1.1180d, bsd.stdev(), 0.001d);
+        assertEquals(5, bsd.sumOfDeviations(), 0.001d);
+        
+        //check that it clears properly
+        bsd.clear();
+        assertFalse(bsd.iterator().hasNext());
+    }
+
+}



Mime
View raw message