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


Java Keyspace.clear方法代码示例

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


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

示例1: testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));
    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC2", "2");

    Keyspace.clear("Keyspace1");
    KSMetaData meta = KSMetaData.newKeyspace("Keyspace1", "NetworkTopologyStrategy", configOptions, false);
    Schema.instance.setKeyspaceDefinition(meta);

    // endpoints in DC1 should not have primary range
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assertTrue(primaryRanges.isEmpty());

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name,
                                                                               InetAddress.getByName("127.0.0.2"));
    assertTrue(primaryRanges.isEmpty());

    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertTrue(primaryRanges.size() == 2);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertTrue(primaryRanges.size() == 2);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:39,代码来源:StorageServiceServerTest.java

示例2: dropKeyspace

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
public void dropKeyspace(String ksName)
{
    KeyspaceMetadata ksm = Schema.instance.getKSMetaData(ksName);
    String snapshotName = Keyspace.getTimestampedSnapshotName(ksName);

    CompactionManager.instance.interruptCompactionFor(ksm.tablesAndViews(), true);

    Keyspace keyspace = Keyspace.open(ksm.name);

    // remove all cfs from the keyspace instance.
    List<UUID> droppedCfs = new ArrayList<>();
    for (CFMetaData cfm : ksm.tablesAndViews())
    {
        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfm.cfName);

        unload(cfm);

        if (DatabaseDescriptor.isAutoSnapshot())
            cfs.snapshot(snapshotName);
        Keyspace.open(ksm.name).dropCf(cfm.cfId);

        droppedCfs.add(cfm.cfId);
    }

    // remove the keyspace from the static instances.
    Keyspace.clear(ksm.name);
    clearKeyspaceMetadata(ksm);

    Keyspace.writeOrder.awaitNewBarrier();

    // force a new segment in the CL
    CommitLog.instance.forceRecycleAllSegments(droppedCfs);

    MigrationManager.instance.notifyDropKeyspace(ksm);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:36,代码来源:Schema.java

示例3: testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));
    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC2", "2");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");

    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.setKeyspaceMetadata(meta);

    // endpoints in DC1 should not have primary range
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assertTrue(primaryRanges.isEmpty());

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name,
                                                                               InetAddress.getByName("127.0.0.2"));
    assertTrue(primaryRanges.isEmpty());

    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertTrue(primaryRanges.size() == 2);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertTrue(primaryRanges.size() == 2);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:40,代码来源:StorageServiceServerTest.java

示例4: testGetIndexNaturalEndpoint

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testGetIndexNaturalEndpoint() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));

    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> replicationMap = new HashMap<>();
    replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());

    replicationMap.put("DC1", "1");
    replicationMap.put("DC2", "1");

    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
    Schema.instance.setKeyspaceMetadata(meta);

    Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1",
                                                                   new StringToken("CA"),
                                                                   new StringToken("BB"));

    Assert.assertTrue(naturalEndpoint.isPresent());
    Assert.assertEquals(InetAddress.getByName("127.0.0.2"), naturalEndpoint.get());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:32,代码来源:ViewUtilsTest.java

示例5: testLocalHostPreference

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testLocalHostPreference() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));

    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> replicationMap = new HashMap<>();
    replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());

    replicationMap.put("DC1", "2");
    replicationMap.put("DC2", "2");

    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
    Schema.instance.setKeyspaceMetadata(meta);

    Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1",
                                                                   new StringToken("CA"),
                                                                   new StringToken("BB"));

    Assert.assertTrue(naturalEndpoint.isPresent());
    Assert.assertEquals(InetAddress.getByName("127.0.0.1"), naturalEndpoint.get());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:32,代码来源:ViewUtilsTest.java

示例6: testBaseTokenDoesNotBelongToLocalReplicaShouldReturnEmpty

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testBaseTokenDoesNotBelongToLocalReplicaShouldReturnEmpty() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));

    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> replicationMap = new HashMap<>();
    replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());

    replicationMap.put("DC1", "1");
    replicationMap.put("DC2", "1");

    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
    Schema.instance.setKeyspaceMetadata(meta);

    Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1",
                                                                   new StringToken("AB"),
                                                                   new StringToken("BB"));

    Assert.assertFalse(naturalEndpoint.isPresent());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:31,代码来源:ViewUtilsTest.java

示例7: testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));

    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "1");
    configOptions.put("DC2", "1");

    Keyspace.clear("Keyspace1");
    KSMetaData meta = KSMetaData.newKeyspace("Keyspace1", "NetworkTopologyStrategy", configOptions, false);
    Schema.instance.setKeyspaceDefinition(meta);

    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name,
                                                                                                        InetAddress.getByName("127.0.0.1"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:44,代码来源:StorageServiceServerTest.java

示例8: testPrimaryRangeForEndpointWithinDCWithVnodes

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithVnodes() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    Multimap<InetAddress, Token> dc1 = HashMultimap.create();
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("A"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("E"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("H"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("C"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("I"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("J"));
    metadata.updateNormalTokens(dc1);

    // DC2
    Multimap<InetAddress, Token> dc2 = HashMultimap.create();
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("B"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("G"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("L"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("D"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("F"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("K"));
    metadata.updateNormalTokens(dc2);

    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "1");
    configOptions.put("DC2", "2");

    Keyspace.clear("Keyspace1");
    KSMetaData meta = KSMetaData.newKeyspace("Keyspace1", "NetworkTopologyStrategy", configOptions, false);
    Schema.instance.setKeyspaceDefinition(meta);

    // endpoints in DC1 should have primary ranges which also cover DC2
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assertEquals(8, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));

    // endpoints in DC1 should have primary ranges which also cover DC2
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assertEquals(4, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));

    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertEquals(4, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
    // because /127.0.0.4 holds token "B" which is the next to token "A" from /127.0.0.1,
    // the node covers range (L, A]
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertTrue(primaryRanges.size() == 8);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
    // ranges from /127.0.0.1
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
    // the next token to "H" in DC2 is "K" in /127.0.0.5, so (G, H] goes to /127.0.0.5
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));
    // ranges from /127.0.0.2
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:79,代码来源:StorageServiceServerTest.java

示例9: testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));

    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));

    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "1");
    configOptions.put("DC2", "1");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");

    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.setKeyspaceMetadata(meta);

    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name,
                                                                                                        InetAddress.getByName("127.0.0.1"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:45,代码来源:StorageServiceServerTest.java

示例10: testPrimaryRangeForEndpointWithinDCWithVnodes

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testPrimaryRangeForEndpointWithinDCWithVnodes() throws Exception
{
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();

    // DC1
    Multimap<InetAddress, Token> dc1 = HashMultimap.create();
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("A"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("E"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("H"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("C"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("I"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("J"));
    metadata.updateNormalTokens(dc1);

    // DC2
    Multimap<InetAddress, Token> dc2 = HashMultimap.create();
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("B"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("G"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("L"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("D"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("F"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("K"));
    metadata.updateNormalTokens(dc2);

    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "1");
    configOptions.put("DC2", "2");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");

    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.setKeyspaceMetadata(meta);

    // endpoints in DC1 should have primary ranges which also cover DC2
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assertEquals(8, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));

    // endpoints in DC1 should have primary ranges which also cover DC2
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assertEquals(4, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));

    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertEquals(4, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
    // because /127.0.0.4 holds token "B" which is the next to token "A" from /127.0.0.1,
    // the node covers range (L, A]
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));

    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertTrue(primaryRanges.size() == 8);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
    // ranges from /127.0.0.1
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
    // the next token to "H" in DC2 is "K" in /127.0.0.5, so (G, H] goes to /127.0.0.5
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));
    // ranges from /127.0.0.2
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:80,代码来源:StorageServiceServerTest.java


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