Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
added check for NTS so as not to set strategy options when in use, ad…
Browse files Browse the repository at this point in the history
…dressing hector-client#358
  • Loading branch information
zznate committed Dec 7, 2011
1 parent a2ba363 commit a8d8f97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.apache.cassandra.thrift.CfDef;
import org.apache.cassandra.thrift.KsDef;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.math.NumberUtils;
Expand All @@ -20,6 +21,7 @@ public class ThriftKsDef implements KeyspaceDefinition {

private static final String REPLICATION_FACTOR = "replication_factor";
public static final String DEF_STRATEGY_CLASS = "org.apache.cassandra.locator.SimpleStrategy";
public static final String NETWORK_TOPOLOGY_STRATEGY = "org.apache.cassandra.locator.NetworkTopologyStrategy";
private final String name;
private String strategyClass;
private Map<String, String> strategyOptions = new HashMap<String, String>();
Expand Down Expand Up @@ -47,8 +49,8 @@ public ThriftKsDef(String keyspaceName, String strategyClass, int replicationFac
public ThriftKsDef(String keyspaceName) {
this.name = keyspaceName;
this.cfDefs = new ArrayList<ColumnFamilyDefinition>();
setReplicationFactor(1);
this.strategyClass = DEF_STRATEGY_CLASS;
setReplicationFactor(1);
}

public ThriftKsDef(KeyspaceDefinition keyspaceDefinition) {
Expand Down Expand Up @@ -119,8 +121,9 @@ public void setStrategyOptions(Map<String, String> strategyOptions) {
}

public void setReplicationFactor(int replicationFactor) {
// Compensate for CASSANDRA-1263 (wasnt my idea)
strategyOptions.put(REPLICATION_FACTOR,Integer.toString(replicationFactor));
if ( !StringUtils.equals(strategyClass, NETWORK_TOPOLOGY_STRATEGY) ) {
strategyOptions.put(REPLICATION_FACTOR,Integer.toString(replicationFactor));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package me.prettyprint.cassandra.service;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.model.BasicKeyspaceDefinition;
import me.prettyprint.cassandra.model.BasicKeyspaceDefinition;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
Expand All @@ -21,14 +17,13 @@
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;

import org.apache.cassandra.thrift.NotFoundException;
import org.apache.cassandra.thrift.TokenRange;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;


public class CassandraClusterTest extends BaseEmbededServerSetupTest {
Expand Down Expand Up @@ -127,6 +122,14 @@ public void testAddDropKeyspace() throws Exception {
assertNotNull(ksid2);
}

@Test
public void testAddKeyspaceNTS() throws Exception {
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("DynKeyspaceNTS", "DynCf");
cassandraCluster.addKeyspace(
new ThriftKsDef("DynKeyspaceNTS", "org.apache.cassandra.locator.NetworkTopologyStrategy", 1, Arrays.asList(cfDef)));

}

@Test
public void testEditKeyspace() throws Exception {

Expand Down

0 comments on commit a8d8f97

Please sign in to comment.