kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 736d1b430942cd7045ce9e2e1433f2bfc7e0e1949e04ad3a1560fef7887b8eef |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-15 19:06 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-15 19:06 +02:00 |
| Parents | ee2c87da056a |
2 files changed
deleted driver-core/src/main/java/com/datastax/driver/core/PoolingOptionsTest.java +0 −94
| @@ -1,94 +0,0 @@ | ||
| 1 | -package com.datastax.driver.core; | |
| 2 | - | |
| 3 | -import org.mockito.Mockito; | |
| 4 | - | |
| 5 | -import org.testng.annotations.Test; | |
| 6 | - | |
| 7 | -import com.datastax.driver.core.Host.State; | |
| 8 | -import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 9 | -import com.datastax.driver.core.policies.LimitingLoadBalancingPolicy; | |
| 10 | -import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 11 | - | |
| 12 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 13 | - | |
| 14 | -public class PoolingOptionsTest { | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * Tests {@link PoolingOptions#refreshConnectedHost(Host)} through a custom load balancing policy. | |
| 18 | - */ | |
| 19 | - @Test(groups = "long") | |
| 20 | - public void should_refresh_single_connected_host() { | |
| 21 | - CCMBridge ccm = null; | |
| 22 | - Cluster cluster = null; | |
| 23 | - try { | |
| 24 | - // This will make the driver use at most 2 hosts, the others will be ignored | |
| 25 | - LimitingLoadBalancingPolicy loadBalancingPolicy = new LimitingLoadBalancingPolicy(new RoundRobinPolicy(), 2, 1); | |
| 26 | - | |
| 27 | - // Setup a 3-host cluster, start only two hosts so that we know in advance which ones the policy will use | |
| 28 | - ccm = CCMBridge.create("test"); | |
| 29 | - ccm.populate(3); | |
| 30 | - ccm.start(1); | |
| 31 | - ccm.start(2); | |
| 32 | - ccm.waitForUp(1); | |
| 33 | - ccm.waitForUp(2); | |
| 34 | - | |
| 35 | - PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); | |
| 36 | - cluster = Cluster.builder() | |
| 37 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 38 | - .withPoolingOptions(poolingOptions) | |
| 39 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 40 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) | |
| 41 | - .build(); | |
| 42 | - | |
| 43 | - Session session = cluster.connect(); | |
| 44 | - | |
| 45 | - assertThat(cluster).usesControlHost(1); | |
| 46 | - assertThat(cluster).host(1) | |
| 47 | - .hasState(State.UP) | |
| 48 | - .isAtDistance(HostDistance.LOCAL); | |
| 49 | - assertThat(cluster).host(2) | |
| 50 | - .hasState(State.UP) | |
| 51 | - .isAtDistance(HostDistance.LOCAL); | |
| 52 | - | |
| 53 | - // Bring host 3 up, its presence should be acknowledged but it should be ignored | |
| 54 | - ccm.start(3); | |
| 55 | - ccm.waitForUp(3); | |
| 56 | - | |
| 57 | - assertThat(cluster).host(1) | |
| 58 | - .hasState(State.UP) | |
| 59 | - .isAtDistance(HostDistance.LOCAL); | |
| 60 | - assertThat(cluster).host(2) | |
| 61 | - .hasState(State.UP) | |
| 62 | - .isAtDistance(HostDistance.LOCAL); | |
| 63 | - assertThat(cluster).host(3) | |
| 64 | - .hasState(State.ADDED) | |
| 65 | - .isAtDistance(HostDistance.IGNORED); | |
| 66 | - assertThat(session).hasNoPoolFor(3); | |
| 67 | - | |
| 68 | - // Kill host 2, host 3 should take its place | |
| 69 | - ccm.stop(2); | |
| 70 | - TestUtils.waitFor(CCMBridge.ipOfNode(3), cluster); | |
| 71 | - | |
| 72 | - assertThat(cluster).host(1) | |
| 73 | - .hasState(State.UP) | |
| 74 | - .isAtDistance(HostDistance.LOCAL); | |
| 75 | - assertThat(cluster).host(2) | |
| 76 | - .hasState(State.DOWN); | |
| 77 | - assertThat(cluster).host(3) | |
| 78 | - .hasState(State.UP) | |
| 79 | - .isAtDistance(HostDistance.LOCAL); | |
| 80 | - assertThat(session).hasPoolFor(3); | |
| 81 | - | |
| 82 | - // This is when refreshConnectedHost should have been invoked, it triggers pool creation when | |
| 83 | - // we switch the node from IGNORED to UP: | |
| 84 | - Mockito.verify(poolingOptions) | |
| 85 | - .refreshConnectedHost(TestUtils.findHost(cluster, 3)); | |
| 86 | - | |
| 87 | - } finally { | |
| 88 | - if (cluster != null) | |
| 89 | - cluster.close(); | |
| 90 | - if (ccm != null) | |
| 91 | - ccm.remove(); | |
| 92 | - } | |
| 93 | - } | |
| 94 | -} |
added driver-core/src/test/java/com/datastax/driver/core/PoolingOptionsTest.java +94 −0
| @@ -0,0 +1,94 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import org.mockito.Mockito; | |
| 4 | + | |
| 5 | +import org.testng.annotations.Test; | |
| 6 | + | |
| 7 | +import com.datastax.driver.core.Host.State; | |
| 8 | +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 9 | +import com.datastax.driver.core.policies.LimitingLoadBalancingPolicy; | |
| 10 | +import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 11 | + | |
| 12 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 13 | + | |
| 14 | +public class PoolingOptionsTest { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Tests {@link PoolingOptions#refreshConnectedHost(Host)} through a custom load balancing policy. | |
| 18 | + */ | |
| 19 | + @Test(groups = "long") | |
| 20 | + public void should_refresh_single_connected_host() { | |
| 21 | + CCMBridge ccm = null; | |
| 22 | + Cluster cluster = null; | |
| 23 | + try { | |
| 24 | + // This will make the driver use at most 2 hosts, the others will be ignored | |
| 25 | + LimitingLoadBalancingPolicy loadBalancingPolicy = new LimitingLoadBalancingPolicy(new RoundRobinPolicy(), 2, 1); | |
| 26 | + | |
| 27 | + // Setup a 3-host cluster, start only two hosts so that we know in advance which ones the policy will use | |
| 28 | + ccm = CCMBridge.create("test"); | |
| 29 | + ccm.populate(3); | |
| 30 | + ccm.start(1); | |
| 31 | + ccm.start(2); | |
| 32 | + ccm.waitForUp(1); | |
| 33 | + ccm.waitForUp(2); | |
| 34 | + | |
| 35 | + PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); | |
| 36 | + cluster = Cluster.builder() | |
| 37 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 38 | + .withPoolingOptions(poolingOptions) | |
| 39 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 40 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) | |
| 41 | + .build(); | |
| 42 | + | |
| 43 | + Session session = cluster.connect(); | |
| 44 | + | |
| 45 | + assertThat(cluster).usesControlHost(1); | |
| 46 | + assertThat(cluster).host(1) | |
| 47 | + .hasState(State.UP) | |
| 48 | + .isAtDistance(HostDistance.LOCAL); | |
| 49 | + assertThat(cluster).host(2) | |
| 50 | + .hasState(State.UP) | |
| 51 | + .isAtDistance(HostDistance.LOCAL); | |
| 52 | + | |
| 53 | + // Bring host 3 up, its presence should be acknowledged but it should be ignored | |
| 54 | + ccm.start(3); | |
| 55 | + ccm.waitForUp(3); | |
| 56 | + | |
| 57 | + assertThat(cluster).host(1) | |
| 58 | + .hasState(State.UP) | |
| 59 | + .isAtDistance(HostDistance.LOCAL); | |
| 60 | + assertThat(cluster).host(2) | |
| 61 | + .hasState(State.UP) | |
| 62 | + .isAtDistance(HostDistance.LOCAL); | |
| 63 | + assertThat(cluster).host(3) | |
| 64 | + .hasState(State.ADDED) | |
| 65 | + .isAtDistance(HostDistance.IGNORED); | |
| 66 | + assertThat(session).hasNoPoolFor(3); | |
| 67 | + | |
| 68 | + // Kill host 2, host 3 should take its place | |
| 69 | + ccm.stop(2); | |
| 70 | + TestUtils.waitFor(CCMBridge.ipOfNode(3), cluster); | |
| 71 | + | |
| 72 | + assertThat(cluster).host(1) | |
| 73 | + .hasState(State.UP) | |
| 74 | + .isAtDistance(HostDistance.LOCAL); | |
| 75 | + assertThat(cluster).host(2) | |
| 76 | + .hasState(State.DOWN); | |
| 77 | + assertThat(cluster).host(3) | |
| 78 | + .hasState(State.UP) | |
| 79 | + .isAtDistance(HostDistance.LOCAL); | |
| 80 | + assertThat(session).hasPoolFor(3); | |
| 81 | + | |
| 82 | + // This is when refreshConnectedHost should have been invoked, it triggers pool creation when | |
| 83 | + // we switch the node from IGNORED to UP: | |
| 84 | + Mockito.verify(poolingOptions) | |
| 85 | + .refreshConnectedHost(TestUtils.findHost(cluster, 3)); | |
| 86 | + | |
| 87 | + } finally { | |
| 88 | + if (cluster != null) | |
| 89 | + cluster.close(); | |
| 90 | + if (ccm != null) | |
| 91 | + ccm.remove(); | |
| 92 | + } | |
| 93 | + } | |
| 94 | +} |