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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations