cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jolynch <...@git.apache.org>
Subject [GitHub] cassandra pull request #283: CASSANDRA-14459: DynamicEndpointSnitch should n...
Date Tue, 27 Nov 2018 17:21:22 GMT
Github user jolynch commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/283#discussion_r236765727
  
    --- Diff: test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java ---
    @@ -19,34 +19,104 @@
     package org.apache.cassandra.locator;
     
     import java.io.IOException;
    +import java.net.UnknownHostException;
     import java.util.*;
     
    -import org.junit.BeforeClass;
    +import org.junit.After;
    +import org.junit.Before;
     import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
     
     import org.apache.cassandra.Util;
     import org.apache.cassandra.config.DatabaseDescriptor;
     import org.apache.cassandra.exceptions.ConfigurationException;
    +import org.apache.cassandra.gms.Gossiper;
    +import org.apache.cassandra.locator.dynamicsnitch.DynamicEndpointSnitchEMA;
    +import org.apache.cassandra.locator.dynamicsnitch.DynamicEndpointSnitchHistogram;
    +import org.apache.cassandra.locator.dynamicsnitch.DynamicEndpointSnitchLegacyHistogram;
    +import org.apache.cassandra.net.LatencyMeasurementType;
    +import org.apache.cassandra.net.async.TestScheduledFuture;
     import org.apache.cassandra.service.StorageService;
     import org.apache.cassandra.utils.FBUtilities;
     
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +
    +@RunWith(Parameterized.class)
     public class DynamicEndpointSnitchTest
     {
    +    private static InetAddressAndPort[] hosts;
    +    // Reduce the update interval significantly so that tests run quickly
    +    private static final long UPDATE_INTERVAL_MS = 10;
    +    // Intentially 31 and a little bit instead of 30 seconds flat so this doesn't divide
evenly into the default
    +    // MAX_PROBE_INTERVAL_MS. Also pretty high so latency probes don't interfere with
the unit tests
    +    private static final long PING_INTERVAL_MS = 31 * 1003;
    +
    +    private final DynamicEndpointSnitch dsnitch;
    +
    +    public DynamicEndpointSnitchTest(DynamicEndpointSnitch dsnitch)
    +    {
    +        this.dsnitch = dsnitch;
    +    }
    +
    +    @Before
    +    public void prepareDES()
    +    {
    +        for (InetAddressAndPort host : hosts)
    +        {
    +            Gossiper.instance.initializeNodeUnsafe(host, UUID.randomUUID(), 1);
    +            Gossiper.instance.realMarkAlive(host, Gossiper.instance.getEndpointStateForEndpoint(host));
    +        }
    +        dsnitch.reset();
    +    }
     
    -    @BeforeClass
    -    public static void setupDD()
    +    @Parameterized.Parameters(name="{index}: {0}")
    +    public static Iterable<?> getDESImplementation() throws UnknownHostException
         {
             DatabaseDescriptor.daemonInitialization();
    +        // do this because SS needs to be initialized before DES can work properly.
    +        StorageService.instance.unsafeInitialize();
    +
    +        hosts = new InetAddressAndPort[] {
    +            FBUtilities.getBroadcastAddressAndPort(),
    +            InetAddressAndPort.getByName("127.0.0.2"),
    +            InetAddressAndPort.getByName("127.0.0.3"),
    +            InetAddressAndPort.getByName("127.0.0.4"),
    +            InetAddressAndPort.getByName("127.0.0.5"),
    +        };
    +
    +        SimpleSnitch ss1 = new SimpleSnitch();
    +        DynamicEndpointSnitch probeDES = new DynamicEndpointSnitchHistogram(ss1, String.valueOf(ss1.hashCode()));
    +        probeDES.applyConfigChanges((int) UPDATE_INTERVAL_MS, (int) PING_INTERVAL_MS,
DatabaseDescriptor.getDynamicBadnessThreshold());
    +
    +        SimpleSnitch ss2 = new SimpleSnitch();
    +        DynamicEndpointSnitch oldDES = new DynamicEndpointSnitchLegacyHistogram(ss2,
String.valueOf(ss2.hashCode()));
    +        oldDES.applyConfigChanges((int) UPDATE_INTERVAL_MS, (int) PING_INTERVAL_MS, DatabaseDescriptor.getDynamicBadnessThreshold());
    +
    +        SimpleSnitch ss3 = new SimpleSnitch();
    +        DynamicEndpointSnitch emaDES = new DynamicEndpointSnitchEMA(ss3, String.valueOf(ss3.hashCode()));
    +        emaDES.applyConfigChanges((int) UPDATE_INTERVAL_MS, (int) PING_INTERVAL_MS, DatabaseDescriptor.getDynamicBadnessThreshold());
    +
    +        return Arrays.asList(probeDES, oldDES, emaDES);
    +    }
    +
    +    @After
    +    public void resetDES()
    +    {
    +        dsnitch.reset();
         }
     
         private static void setScores(DynamicEndpointSnitch dsnitch, int rounds, List<InetAddressAndPort>
hosts, Integer... scores) throws InterruptedException
         {
             for (int round = 0; round < rounds; round++)
             {
                 for (int i = 0; i < hosts.size(); i++)
    -                dsnitch.receiveTiming(hosts.get(i), scores[i]);
    +                dsnitch.receiveTiming(hosts.get(i), scores[i], LatencyMeasurementType.READ);
             }
    -        Thread.sleep(150);
    +        // Slightly higher than the update interval to allow scores to propagate
    +        Thread.sleep(UPDATE_INTERVAL_MS + 10);
    --- End diff --
    
    Yea I mean the status quo was this could be pretty flakey, one of the reasons that I separated
out `updateScores` was so that we can forcibly recalculate scores using it. I went ahead and
switched this method to just forcibly call `updateScores`, I guess we don't need a test that
the threading works?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message