private void createLocksKeyspace() throws ConnectionException { try { KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace(); if ( keyspaceDefinition != null ) { logger.info("Keyspace {} already exists", keyspace.getKeyspaceName()); return; } } catch (ConnectionException ce){ logger.debug( "Received a NotFoundException when attempting to describe keyspace. It does not exist" ); } ImmutableMap.Builder<String, Object> strategyOptions = getKeySpaceProps(); ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder().put("strategy_class", cassandraFig.getLocksKeyspaceStrategy()) .put("strategy_options", strategyOptions.build()).build(); keyspace.createKeyspace(options); logger.info("Keyspace {} created with options {}", keyspace.getKeyspaceName(), options.toString()); }
@Override public OperationResult<SchemaChangeResult> exec(Keyspace ks) throws ConnectionException { return ks.createKeyspace(properties); } });
@Override public OperationResult<SchemaChangeResult> exec(Keyspace ks) throws ConnectionException { return ks.createKeyspace(options, cfs); } });
@Override public OperationResult<SchemaChangeResult> exec(Keyspace ks) throws ConnectionException { return ks.createKeyspace(options); } });
@Test public void keyspaceDescribePartitioner() throws Exception { String keyspaceName = "AstyanaxTestKeyspaceDescribeRing".toLowerCase(); AstyanaxContext<Keyspace> context = AstyanaxContextFactory.getKeyspace(keyspaceName); context.start(); keyspace = context.getClient(); Map<String, Object> options = ImmutableMap.<String, Object>builder() .put("strategy_options", ImmutableMap.<String, Object>builder() .put("replication_factor", "1") .build()) .put("strategy_class", "SimpleStrategy") .build(); keyspace.createKeyspace(options); Thread.sleep(1000); String partitioner = keyspace.describePartitioner(); Assert.assertNotNull(partitioner); keyspace.dropKeyspace(); } }
@Test public void createAndDeleteKeyspace() throws Exception { String keyspaceName = "AstyanaxTestKeyspaceCreateDeleteKS".toLowerCase(); AstyanaxContext<Keyspace> context = AstyanaxContextFactory.getKeyspace(keyspaceName); context.start(); keyspace = context.getClient(); Map<String, Object> options = ImmutableMap.<String, Object>builder() .put("strategy_options", ImmutableMap.<String, Object>builder() .put("replication_factor", "1") .build()) .put("strategy_class", "SimpleStrategy") .build(); keyspace.createKeyspace(options); Thread.sleep(1000); KeyspaceDefinition ksDef = keyspace.describeKeyspace(); Assert.assertTrue(ksDef.getStrategyClass().contains("SimpleStrategy")); keyspace.dropKeyspace(); try { keyspace.describeKeyspace(); Assert.fail("Should have gotten KS not found ex"); } catch(RuntimeException e) { } }
keyspace.createKeyspace(Collections.unmodifiableMap(keyspaceConfig));
.build(); keyspace.createKeyspace(options, cfs);
@Test public void alterCFOptions() throws Exception { String keyspaceName = "AstyanaxTestKeyspaceAlterCFOptions".toLowerCase(); AstyanaxContext<Keyspace> context = AstyanaxContextFactory.getKeyspace(keyspaceName); context.start(); keyspace = context.getClient(); Map<String, Object> options = ImmutableMap.<String, Object>builder() .put("strategy_options", ImmutableMap.<String, Object>builder() .put("replication_factor", "1") .build()) .put("strategy_class", "SimpleStrategy") .build(); keyspace.createKeyspace(options); Thread.sleep(1000); ColumnFamily<String, String> cf = new ColumnFamily<String, String>("testaltercf1", StringSerializer.get(), StringSerializer.get()); keyspace.createColumnFamily(cf, null); Assert.assertEquals(0.1, keyspace.getColumnFamilyProperties("testaltercf1").get("read_repair_chance")); keyspace.updateColumnFamily(cf, ImmutableMap.<String, Object>builder() .put("read_repair_chance", 0.2) .build()); Assert.assertEquals(0.2, keyspace.getColumnFamilyProperties("testaltercf1").get("read_repair_chance")); keyspace.dropKeyspace(); }
.build(); keyspace.createKeyspace(options); .build(); keyspace.createKeyspace(options);
.build(); keyspace.createKeyspace(options); Thread.sleep(1000); .build(); keyspace.createKeyspace(options); Thread.sleep(1000);
.build(); keyspace.createKeyspace(options); Thread.sleep(1000);
props.setProperty("strategy_class", "SimpleStrategy"); keyspace.createKeyspace(props); Thread.sleep(1000); props.setProperty("strategy_class", "NetworkTopologyStrategy"); keyspace.createKeyspace(props); Thread.sleep(1000);
keyspace.createKeyspace(ksOptions);
keyspace.createKeyspace(ksOptions);
keyspace.createKeyspace(ImmutableMap.<String, Object>builder() .put("strategy_options", ImmutableMap.<String, Object>of("replication_factor", "1")) .put("strategy_class", "SimpleStrategy") keyspace.createKeyspace(ImmutableMap.<String, Object>builder() .put("strategy_options", ImmutableMap.<String, Object>of("replication_factor", "1")) .put("strategy_class", "SimpleStrategy")