Search in sources :

Example 11 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class TriggersSchemaTest method addNewCfWithTriggerToKs.

@Test
public void addNewCfWithTriggerToKs() throws Exception {
    KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1));
    MigrationManager.announceNewKeyspace(ksm);
    TableMetadata metadata = CreateTableStatement.parse(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName).triggers(Triggers.of(TriggerMetadata.create(triggerName, triggerClass))).build();
    MigrationManager.announceNewTable(metadata);
    metadata = Schema.instance.getTableMetadata(ksName, cfName);
    assertFalse(metadata.triggers.isEmpty());
    assertEquals(1, metadata.triggers.size());
    assertEquals(TriggerMetadata.create(triggerName, triggerClass), metadata.triggers.get(triggerName).get());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) Test(org.junit.Test)

Example 12 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class TriggersSchemaTest method removeTriggerFromCf.

@Test
public void removeTriggerFromCf() throws Exception {
    TriggerMetadata td = TriggerMetadata.create(triggerName, triggerClass);
    TableMetadata tm = CreateTableStatement.parse(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName).triggers(Triggers.of(td)).build();
    KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1), Tables.of(tm));
    MigrationManager.announceNewKeyspace(ksm);
    TableMetadata tm1 = Schema.instance.getTableMetadata(ksName, cfName);
    TableMetadata tm2 = tm1.unbuild().triggers(tm1.triggers.without(triggerName)).build();
    MigrationManager.announceTableUpdate(tm2);
    TableMetadata tm3 = Schema.instance.getTableMetadata(ksName, cfName);
    assertTrue(tm3.triggers.isEmpty());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) TriggerMetadata(org.apache.cassandra.schema.TriggerMetadata) Test(org.junit.Test)

Example 13 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class ViewUtilsTest method testBaseTokenDoesNotBelongToLocalReplicaShouldReturnEmpty.

@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.load(meta);
    Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1", new StringToken("AB"), new StringToken("BB"));
    Assert.assertFalse(naturalEndpoint.isPresent());
}
Also used : NetworkTopologyStrategy(org.apache.cassandra.locator.NetworkTopologyStrategy) HashMap(java.util.HashMap) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) InetAddress(java.net.InetAddress) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 14 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class ViewUtilsTest method testGetIndexNaturalEndpoint.

@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.load(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());
}
Also used : NetworkTopologyStrategy(org.apache.cassandra.locator.NetworkTopologyStrategy) HashMap(java.util.HashMap) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) InetAddress(java.net.InetAddress) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 15 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class ViewUtilsTest method testLocalHostPreference.

@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.load(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());
}
Also used : NetworkTopologyStrategy(org.apache.cassandra.locator.NetworkTopologyStrategy) HashMap(java.util.HashMap) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) InetAddress(java.net.InetAddress) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Aggregations

KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)30 Test (org.junit.Test)17 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)12 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)11 Range (org.apache.cassandra.dht.Range)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 InetAddress (java.net.InetAddress)6 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)6 Token (org.apache.cassandra.dht.Token)6 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)4 HashMap (java.util.HashMap)3 UserType (org.apache.cassandra.db.marshal.UserType)3 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)3 TriggerMetadata (org.apache.cassandra.schema.TriggerMetadata)3 JavaBasedUDFunction (org.apache.cassandra.cql3.functions.JavaBasedUDFunction)1 UDAggregate (org.apache.cassandra.cql3.functions.UDAggregate)1 UDFunction (org.apache.cassandra.cql3.functions.UDFunction)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)1 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)1