当前位置: 首页>>代码示例>>Java>>正文


Java Util.createInitialRing方法代码示例

本文整理汇总了Java中org.apache.cassandra.Util.createInitialRing方法的典型用法代码示例。如果您正苦于以下问题:Java Util.createInitialRing方法的具体用法?Java Util.createInitialRing怎么用?Java Util.createInitialRing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.Util的用法示例。


在下文中一共展示了Util.createInitialRing方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStateJumpToLeft

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToLeft() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = RandomPartitioner.instance;
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring of 6 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 7);

    // node hosts.get(2) goes jumps to left
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(endpointTokens.get(2)), Gossiper.computeExpireTime()));

    assertFalse(tmd.isMember(hosts.get(2)));

    // node hosts.get(4) goes to bootstrap
    Gossiper.instance.injectApplicationState(hosts.get(3), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(3), ApplicationState.STATUS, valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));

    assertFalse(tmd.isMember(hosts.get(3)));
    assertEquals(1, tmd.getBootstrapTokens().size());
    assertEquals(hosts.get(3), tmd.getBootstrapTokens().get(keyTokens.get(1)));

    // and then directly to 'left'
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));

    assertTrue(tmd.getBootstrapTokens().size() == 0);
    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:41,代码来源:LeaveAndBootstrapTest.java

示例2: testStateJumpToLeft

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToLeft() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring of 6 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 7);

    // node hosts.get(2) goes jumps to left
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(endpointTokens.get(2)), Gossiper.computeExpireTime()));

    assertFalse(tmd.isMember(hosts.get(2)));

    // node hosts.get(4) goes to bootstrap
    Gossiper.instance.injectApplicationState(hosts.get(3), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(3), ApplicationState.STATUS, valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));

    assertFalse(tmd.isMember(hosts.get(3)));
    assertEquals(1, tmd.getBootstrapTokens().size());
    assertEquals(hosts.get(3), tmd.getBootstrapTokens().get(keyTokens.get(1)));

    // and then directly to 'left'
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));

    assertTrue(tmd.getBootstrapTokens().size() == 0);
    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:41,代码来源:LeaveAndBootstrapTest.java

示例3: testStateChangeOnRemovedNode

import org.apache.cassandra.Util; //导入方法依赖的package包/类
/**
 * Tests that the system.peers table is not updated after a node has been removed. (See CASSANDRA-6053)
 */
@Test
public void testStateChangeOnRemovedNode() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    // create a ring of 2 nodes
    ArrayList<Token> endpointTokens = new ArrayList<>();
    List<InetAddress> hosts = new ArrayList<>();
    Util.createInitialRing(ss, partitioner, endpointTokens, new ArrayList<Token>(), hosts, new ArrayList<UUID>(), 2);

    InetAddress toRemove = hosts.get(1);
    SystemKeyspace.updatePeerInfo(toRemove, "data_center", "dc42");
    SystemKeyspace.updatePeerInfo(toRemove, "rack", "rack42");
    assertEquals("rack42", SystemKeyspace.loadDcRackInfo().get(toRemove).get("rack"));

    // mark the node as removed
    Gossiper.instance.injectApplicationState(toRemove, ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(endpointTokens.get(1)), Gossiper.computeExpireTime()));
    assertTrue(Gossiper.instance.isDeadState(Gossiper.instance.getEndpointStateForEndpoint(hosts.get(1))));

    // state changes made after the endpoint has left should be ignored
    ss.onChange(hosts.get(1), ApplicationState.RACK,
            valueFactory.rack("rack9999"));
    assertEquals("rack42", SystemKeyspace.loadDcRackInfo().get(toRemove).get("rack"));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:30,代码来源:LeaveAndBootstrapTest.java

示例4: testLargeGenerationJump

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testLargeGenerationJump() throws UnknownHostException, InterruptedException
{
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 2);
    InetAddress remoteHostAddress = hosts.get(1);

    EndpointState initialRemoteState = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress);
    HeartBeatState initialRemoteHeartBeat = initialRemoteState.getHeartBeatState();

    //Util.createInitialRing should have initialized remoteHost's HeartBeatState's generation to 1
    assertEquals(initialRemoteHeartBeat.getGeneration(), 1);

    HeartBeatState proposedRemoteHeartBeat = new HeartBeatState(initialRemoteHeartBeat.getGeneration() + Gossiper.MAX_GENERATION_DIFFERENCE + 1);
    EndpointState proposedRemoteState = new EndpointState(proposedRemoteHeartBeat);

    Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, proposedRemoteState));

    //The generation should have been updated because it isn't over Gossiper.MAX_GENERATION_DIFFERENCE in the future
    HeartBeatState actualRemoteHeartBeat = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress).getHeartBeatState();
    assertEquals(proposedRemoteHeartBeat.getGeneration(), actualRemoteHeartBeat.getGeneration());

    //Propose a generation 10 years in the future - this should be rejected.
    HeartBeatState badProposedRemoteHeartBeat = new HeartBeatState((int) (System.currentTimeMillis()/1000) + Gossiper.MAX_GENERATION_DIFFERENCE * 10);
    EndpointState badProposedRemoteState = new EndpointState(badProposedRemoteHeartBeat);

    Gossiper.instance.applyStateLocally(ImmutableMap.of(remoteHostAddress, badProposedRemoteState));

    actualRemoteHeartBeat = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress).getHeartBeatState();

    //The generation should not have been updated because it is over Gossiper.MAX_GENERATION_DIFFERENCE in the future
    assertEquals(proposedRemoteHeartBeat.getGeneration(), actualRemoteHeartBeat.getGeneration());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:33,代码来源:GossiperTest.java

示例5: testConvictAfterLeft

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testConvictAfterLeft() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<>();
    ArrayList<Token> keyTokens = new ArrayList<>();
    List<InetAddress> hosts = new ArrayList<>();
    List<UUID> hostIds = new ArrayList<>();

    // we want to convict if there is any heartbeat data present in the FD
    DatabaseDescriptor.setPhiConvictThreshold(0);

    // create a ring of 2 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 3);

    InetAddress leftHost = hosts.get(1);

    FailureDetector.instance.report(leftHost);

    // trigger handleStateLeft in StorageService
    ss.onChange(leftHost, ApplicationState.STATUS,
                valueFactory.left(Collections.singleton(endpointTokens.get(1)), Gossiper.computeExpireTime()));

    // confirm that handleStateLeft was called and leftEndpoint was removed from TokenMetadata
    assertFalse("Left endpoint not removed from TokenMetadata", tmd.isMember(leftHost));

    // confirm the FD's history for leftHost didn't get wiped by status jump to LEFT
    FailureDetector.instance.interpret(leftHost);
    assertFalse("Left endpoint not convicted", FailureDetector.instance.isAlive(leftHost));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:36,代码来源:FailureDetectorTest.java

示例6: testStateJumpToLeft

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToLeft() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring of 6 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 7);

    // node hosts.get(2) goes jumps to left
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(endpointTokens.get(2)), Gossiper.computeExpireTime()));

    assertFalse(tmd.isMember(hosts.get(2)));

    // node hosts.get(4) goes to bootstrap
    Gossiper.instance.injectApplicationState(hosts.get(3), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(3), ApplicationState.STATUS, valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));

    assertFalse(tmd.isMember(hosts.get(3)));
    assertTrue(tmd.getBootstrapTokens().size() == 1);
    assertTrue(tmd.getBootstrapTokens().get(keyTokens.get(1)).equals(hosts.get(3)));

    // and then directly to 'left'
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));

    assertTrue(tmd.getBootstrapTokens().size() == 0);
    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:41,代码来源:LeaveAndBootstrapTest.java

示例7: setup

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Before
public void setup() throws IOException, ConfigurationException
{
    tmd.clearUnsafe();

    // create a ring of 5 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);

    MessagingService.instance().listen();
    Gossiper.instance.start(1);
    removalhost = hosts.get(5);
    hosts.remove(removalhost);
    removalId = hostIds.get(5);
    hostIds.remove(removalId);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:16,代码来源:RemoveTest.java

示例8: testMoveWithPendingRangesNetworkStrategyRackAwareThirtyNodes

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testMoveWithPendingRangesNetworkStrategyRackAwareThirtyNodes() throws Exception
{
    StorageService ss = StorageService.instance;
    final int RING_SIZE = 60;

    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
    ArrayList<Token> endpointTokens = new ArrayList<>();
    ArrayList<Token> keyTokens = new ArrayList<>();
    List<InetAddress> hosts = new ArrayList<>();
    List<UUID> hostIds = new ArrayList<>();

    for(int i=0; i < RING_SIZE/2; i++)
    {
        endpointTokens.add(new BigIntegerToken(String.valueOf(10 * i)));
        endpointTokens.add(new BigIntegerToken(String.valueOf((10 * i) + 1)));
    }
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, RING_SIZE);
    PendingRangeCalculatorService.instance.blockUntilFinished();

    //Moving Endpoint 127.0.0.37 in RAC1 with current token 180
    int MOVING_NODE = 36;
    moveHost(hosts.get(MOVING_NODE), 215, tmd, valueFactory);

    assertPendingRanges(tmd, generatePendingRanges(generatePendingMapEntry(150, 151, "127.0.0.43"),
            generatePendingMapEntry(151, 160, "127.0.0.43"),generatePendingMapEntry(160, 161, "127.0.0.43"),
            generatePendingMapEntry(161, 170, "127.0.0.43"), generatePendingMapEntry(170, 171, "127.0.0.43"),
            generatePendingMapEntry(171, 180, "127.0.0.43"), generatePendingMapEntry(210, 211, "127.0.0.37"),
            generatePendingMapEntry(211, 215, "127.0.0.37")), Network_33_KeyspaceName);

    finishMove(hosts.get(MOVING_NODE), 215, tmd);

    //Moving it back to original spot
    moveHost(hosts.get(MOVING_NODE), 180, tmd, valueFactory);
    finishMove(hosts.get(MOVING_NODE), 180, tmd);

}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:40,代码来源:MoveTest.java

示例9: testStateJumpToNormal

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToNormal() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    IPartitioner partitioner = RandomPartitioner.instance;
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 6 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);

    // node 2 leaves
    Token newToken = positionToken(7);
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.moving(newToken));

    assertTrue(tmd.isMoving(hosts.get(2)));
    assertEquals(endpointTokens.get(2), tmd.getToken(hosts.get(2)));

    // back to normal
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(newToken)));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(newToken)));

    assertTrue(tmd.getMovingEndpoints().isEmpty());
    assertEquals(newToken, tmd.getToken(hosts.get(2)));

    newToken = positionToken(8);
    // node 2 goes through leave and left and then jumps to normal at its new token
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.moving(newToken));
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(newToken)));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(newToken)));

    assertTrue(tmd.getBootstrapTokens().isEmpty());
    assertTrue(tmd.getMovingEndpoints().isEmpty());
    assertEquals(newToken, tmd.getToken(hosts.get(2)));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:41,代码来源:MoveTest.java

示例10: testRemovingStatusForNonMember

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testRemovingStatusForNonMember()  throws UnknownHostException
{
    // create a ring of 1 node
    StorageService ss = StorageService.instance;
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
    Util.createInitialRing(ss, partitioner, new ArrayList<Token>(), new ArrayList<Token>(), new ArrayList<InetAddress>(), new ArrayList<UUID>(), 1);

    // make a REMOVING state change on a non-member endpoint; without the CASSANDRA-6564 fix, this
    // would result in an ArrayIndexOutOfBoundsException
    ss.onChange(InetAddress.getByName("192.168.1.42"), ApplicationState.STATUS, valueFactory.removingNonlocal(UUID.randomUUID()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:13,代码来源:LeaveAndBootstrapTest.java

示例11: testStateJumpToLeaving

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToLeaving() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = RandomPartitioner.instance;
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 5 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);

    // node 2 leaves with _different_ token
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(0))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(0))));

    assertEquals(keyTokens.get(0), tmd.getToken(hosts.get(2)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertNull(tmd.getEndpoint(endpointTokens.get(2)));

    // go to boostrap
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(2),
                ApplicationState.STATUS,
                valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));

    assertFalse(tmd.isLeaving(hosts.get(2)));
    assertEquals(1, tmd.getBootstrapTokens().size());
    assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(1)));

    // jump to leaving again
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(1))));

    assertEquals(hosts.get(2), tmd.getEndpoint(keyTokens.get(1)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertTrue(tmd.getBootstrapTokens().isEmpty());

    // go to state left
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));

    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:50,代码来源:LeaveAndBootstrapTest.java

示例12: testStateJumpToBootstrap

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToBootstrap() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 5 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 7);

    // node 2 leaves
    ss.onChange(hosts.get(2),
                ApplicationState.STATUS,
                valueFactory.leaving(Collections.singleton(endpointTokens.get(2))));

    // don't bother to test pending ranges here, that is extensively tested by other
    // tests. Just check that the node is in appropriate lists.
    assertTrue(tmd.isMember(hosts.get(2)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertTrue(tmd.getBootstrapTokens().isEmpty());

    // Bootstrap the node immedidiately to keyTokens.get(4) without going through STATE_LEFT
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(4))));
    ss.onChange(hosts.get(2),
                ApplicationState.STATUS,
                valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(4))));

    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
    assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(4)));

    // Bootstrap node hosts.get(3) to keyTokens.get(1)
    Gossiper.instance.injectApplicationState(hosts.get(3), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(3),
                ApplicationState.STATUS,
                valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));

    assertFalse(tmd.isMember(hosts.get(3)));
    assertFalse(tmd.isLeaving(hosts.get(3)));
    assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(4)));
    assertEquals(hosts.get(3), tmd.getBootstrapTokens().get(keyTokens.get(1)));

    // Bootstrap node hosts.get(2) further to keyTokens.get(3)
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(3))));
    ss.onChange(hosts.get(2),
                ApplicationState.STATUS,
                valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(3))));

    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
    assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(3)));
    assertNull(tmd.getBootstrapTokens().get(keyTokens.get(4)));
    assertEquals(hosts.get(3), tmd.getBootstrapTokens().get(keyTokens.get(1)));

    // Go to normal again for both nodes
    Gossiper.instance.injectApplicationState(hosts.get(3), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(2))));
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(3))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(3))));
    ss.onChange(hosts.get(3), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(2))));

    assertTrue(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
    assertEquals(keyTokens.get(3), tmd.getToken(hosts.get(2)));
    assertTrue(tmd.isMember(hosts.get(3)));
    assertFalse(tmd.isLeaving(hosts.get(3)));
    assertEquals(keyTokens.get(2), tmd.getToken(hosts.get(3)));

    assertTrue(tmd.getBootstrapTokens().isEmpty());
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:77,代码来源:LeaveAndBootstrapTest.java

示例13: testStateJumpToNormal

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToNormal() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 5 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);

    // node 2 leaves
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(endpointTokens.get(2))));

    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertEquals(endpointTokens.get(2), tmd.getToken(hosts.get(2)));

    // back to normal
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(2))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(2))));

    assertTrue(tmd.getLeavingEndpoints().isEmpty());
    assertEquals(keyTokens.get(2), tmd.getToken(hosts.get(2)));

    // node 3 goes through leave and left and then jumps to normal at its new token
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(2))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(keyTokens.get(2)), Gossiper.computeExpireTime()));
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(4))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(4))));

    assertTrue(tmd.getBootstrapTokens().isEmpty());
    assertTrue(tmd.getLeavingEndpoints().isEmpty());
    assertEquals(keyTokens.get(4), tmd.getToken(hosts.get(2)));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:42,代码来源:LeaveAndBootstrapTest.java

示例14: testStateJumpToLeaving

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToLeaving() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 5 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);

    // node 2 leaves with _different_ token
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(0))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(0))));

    assertEquals(keyTokens.get(0), tmd.getToken(hosts.get(2)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertNull(tmd.getEndpoint(endpointTokens.get(2)));

    // go to boostrap
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(2),
                ApplicationState.STATUS,
                valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));

    assertFalse(tmd.isLeaving(hosts.get(2)));
    assertEquals(1, tmd.getBootstrapTokens().size());
    assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(1)));

    // jump to leaving again
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(1))));

    assertEquals(hosts.get(2), tmd.getEndpoint(keyTokens.get(1)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertTrue(tmd.getBootstrapTokens().isEmpty());

    // go to state left
    ss.onChange(hosts.get(2), ApplicationState.STATUS,
            valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));

    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(hosts.get(2)));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:50,代码来源:LeaveAndBootstrapTest.java

示例15: testStateJumpToNormal

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testStateJumpToNormal() throws UnknownHostException
{
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 6 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);

    // node 2 leaves
    Token newToken = positionToken(7);
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.moving(newToken));

    assertTrue(tmd.isMoving(hosts.get(2)));
    assertTrue(tmd.getToken(hosts.get(2)).equals(endpointTokens.get(2)));

    // back to normal
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(newToken)));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(newToken)));

    assertTrue(tmd.getMovingEndpoints().isEmpty());
    assertTrue(tmd.getToken(hosts.get(2)).equals(newToken));

    newToken = positionToken(8);
    // node 2 goes through leave and left and then jumps to normal at its new token
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.moving(newToken));
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(newToken)));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(newToken)));

    assertTrue(tmd.getBootstrapTokens().isEmpty());
    assertTrue(tmd.getMovingEndpoints().isEmpty());
    assertTrue(tmd.getToken(hosts.get(2)).equals(newToken));
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:42,代码来源:MoveTest.java


注:本文中的org.apache.cassandra.Util.createInitialRing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。