Search in sources :

Example 1 with Strategy

use of org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy in project cassandra by apache.

the class TopologyChangeTest method testRestartNode.

@Test
public void testRestartNode() throws Throwable {
    try (Cluster control = init(Cluster.build().withNodes(3).withNodeProvisionStrategy(strategy).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start());
        com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
        Session session = cluster.connect()) {
        EventStateListener eventStateListener = new EventStateListener();
        session.getCluster().register(eventStateListener);
        control.get(3).shutdown().get();
        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> Assert.assertEquals(2, cluster.getMetadata().getAllHosts().stream().filter(h -> h.isUp()).count()));
        control.get(3).startup();
        await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> Assert.assertEquals(3, cluster.getMetadata().getAllHosts().stream().filter(h -> h.isUp()).count()));
        // DOWN UP can also be seen if the jvm is slow and connections are closed, but make sure it at least happens once
        // given the node restarts
        assertThat(eventStateListener.events).containsSequence(new Event(Down, control.get(3)), new Event(Up, control.get(3)));
    }
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Down(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Down) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) Event(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.Event) Session(com.datastax.driver.core.Session) Parameterized(org.junit.runners.Parameterized) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) OneNetworkInterface(org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy.OneNetworkInterface) Awaitility.await(org.awaitility.Awaitility.await) Collection(java.util.Collection) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MultipleNetworkInterfaces(org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy.MultipleNetworkInterfaces) Remove(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Remove) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Host(com.datastax.driver.core.Host) Up(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Up) Strategy(org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Event(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.Event) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

Host (com.datastax.driver.core.Host)1 Session (com.datastax.driver.core.Session)1 InetSocketAddress (java.net.InetSocketAddress)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 TimeUnit (java.util.concurrent.TimeUnit)1 Cluster (org.apache.cassandra.distributed.Cluster)1 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)1 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)1 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)1 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)1 Strategy (org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy)1 MultipleNetworkInterfaces (org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy.MultipleNetworkInterfaces)1 OneNetworkInterface (org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy.OneNetworkInterface)1 Event (org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.Event)1 Down (org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Down)1 Remove (org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Remove)1