Skip to content

Commit

Permalink
Merge pull request #271 from sylwiaszunejko/drop_simple_strategy
Browse files Browse the repository at this point in the history
Switch tests from SimpleStrategy to NetworkTopologyStrategy
  • Loading branch information
sylwiaszunejko authored Sep 24, 2024
2 parents 279765c + a51f338 commit eaad45e
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 129 deletions.
8 changes: 4 additions & 4 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2112,15 +2112,15 @@ func TestGetKeyspaceMetadata(t *testing.T) {
if keyspaceMetadata.Name != "gocql_test" {
t.Errorf("Expected keyspace name to be 'gocql' but was '%s'", keyspaceMetadata.Name)
}
if keyspaceMetadata.StrategyClass != "org.apache.cassandra.locator.SimpleStrategy" {
t.Errorf("Expected replication strategy class to be 'org.apache.cassandra.locator.SimpleStrategy' but was '%s'", keyspaceMetadata.StrategyClass)
if keyspaceMetadata.StrategyClass != "org.apache.cassandra.locator.NetworkTopologyStrategy" {
t.Errorf("Expected replication strategy class to be 'org.apache.cassandra.locator.NetworkTopologyStrategy' but was '%s'", keyspaceMetadata.StrategyClass)
}
if keyspaceMetadata.StrategyOptions == nil {
t.Error("Expected replication strategy options map but was nil")
}
rfStr, ok := keyspaceMetadata.StrategyOptions["replication_factor"]
rfStr, ok := keyspaceMetadata.StrategyOptions["datacenter1"]
if !ok {
t.Fatalf("Expected strategy option 'replication_factor' but was not found in %v", keyspaceMetadata.StrategyOptions)
t.Fatalf("Expected strategy option 'datacenter1' but was not found in %v", keyspaceMetadata.StrategyOptions)
}
rfInt, err := strconv.Atoi(rfStr.(string))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func createKeyspace(tb testing.TB, cluster *ClusterConfig, keyspace string) {

err = createTable(session, fmt.Sprintf(`CREATE KEYSPACE %s
WITH replication = {
'class' : 'SimpleStrategy',
'class' : 'NetworkTopologyStrategy',
'replication_factor' : %d
}`, keyspace, *flagRF))

Expand Down
2 changes: 1 addition & 1 deletion control_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestUnixSockets(t *testing.T) {

err = createTable(sess, fmt.Sprintf(`CREATE KEYSPACE %s
WITH replication = {
'class' : 'SimpleStrategy',
'class' : 'NetworkTopologyStrategy',
'replication_factor' : 1
}`, keyspace))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion keyspace_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestKeyspaceTable(t *testing.T) {

err = createTable(session, fmt.Sprintf(`CREATE KEYSPACE %s
WITH replication = {
'class' : 'SimpleStrategy',
'class' : 'NetworkTopologyStrategy',
'replication_factor' : 1
}`, keyspace))

Expand Down
2 changes: 1 addition & 1 deletion testdata/recreate/aggregates.cql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE KEYSPACE gocqlx_aggregates WITH replication = {
'class': 'SimpleStrategy',
'class': 'NetworkTopologyStrategy',
'replication_factor': '2'
};

Expand Down
50 changes: 21 additions & 29 deletions testdata/recreate/aggregates_golden.cql
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
CREATE KEYSPACE gocqlx_aggregates WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '2'
};

CREATE FUNCTION gocqlx_aggregates.avgstate (state
tuple<int, double>, val
double)
CALLED ON NULL INPUT
RETURNS frozen<tuple<int, double>>
LANGUAGE lua
AS $$
return { state[1]+1, state[2]+val }
$$;

CREATE FUNCTION gocqlx_aggregates.avgfinal (state
tuple<int, double>)
CALLED ON NULL INPUT
RETURNS double
LANGUAGE lua
AS $$
CREATE KEYSPACE gocqlx_aggregates WITH replication = {'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'datacenter1': '2'} AND durable_writes = true;
CREATE FUNCTION gocqlx_aggregates.avgfinal(state frozen<tuple<int, double>>)
CALLED ON NULL INPUT
RETURNS double
LANGUAGE lua
AS $$
r=0
r=state[2]
r=r/state[1]
return r
$$;

CREATE AGGREGATE gocqlx_aggregates.average(
double)
SFUNC avgstate
STYPE tuple<int, double>
FINALFUNC avgfinal
INITCOND (0, 0);

$$;
CREATE FUNCTION gocqlx_aggregates.avgstate(state frozen<tuple<int, double>>, val double)
CALLED ON NULL INPUT
RETURNS frozen<tuple<int, double>>
LANGUAGE lua
AS $$
return { state[1]+1, state[2]+val }

$$;
CREATE AGGREGATE gocqlx_aggregates.average(double)
SFUNC avgstate
STYPE frozen<tuple<int, double>>
FINALFUNC avgfinal
INITCOND (0, 0);
2 changes: 1 addition & 1 deletion testdata/recreate/index.cql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE KEYSPACE gocqlx_idx WITH replication = {
'class': 'SimpleStrategy',
'class': 'NetworkTopologyStrategy',
'replication_factor': '2'
};

Expand Down
19 changes: 8 additions & 11 deletions testdata/recreate/index_golden.cql
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
CREATE KEYSPACE gocqlx_idx WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '2'
};

CREATE KEYSPACE gocqlx_idx WITH replication = {'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'datacenter1': '2'} AND durable_writes = true;
CREATE TABLE gocqlx_idx.menus (
location text,
name text,
Expand All @@ -11,16 +7,17 @@ CREATE TABLE gocqlx_idx.menus (
PRIMARY KEY (location, name)
) WITH CLUSTERING ORDER BY (name ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys':'ALL','rows_per_partition':'ALL'}
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE';

CREATE INDEX menus_name_idx ON gocqlx_idx.menus (name);
AND speculative_retry = '99.0PERCENTILE'
AND paxos_grace_seconds = 864000
AND tombstone_gc = {'mode': 'timeout', 'propagation_delay_in_seconds': '3600'};
CREATE INDEX menus_name_idx ON gocqlx_idx.menus(name);
2 changes: 1 addition & 1 deletion testdata/recreate/keyspace.cql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE KEYSPACE gocqlx_keyspace WITH replication = {
'class': 'SimpleStrategy',
'class': 'NetworkTopologyStrategy',
'replication_factor': '2'
};
5 changes: 1 addition & 4 deletions testdata/recreate/keyspace_golden.cql
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
CREATE KEYSPACE gocqlx_keyspace WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '2'
};
CREATE KEYSPACE gocqlx_keyspace WITH replication = {'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'datacenter1': '2'} AND durable_writes = true;
2 changes: 1 addition & 1 deletion testdata/recreate/materialized_views.cql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE KEYSPACE gocqlx_mv WITH replication = {
'class': 'SimpleStrategy',
'class': 'NetworkTopologyStrategy',
'replication_factor': '2'
};

Expand Down
50 changes: 24 additions & 26 deletions testdata/recreate/materialized_views_golden.cql
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
CREATE KEYSPACE gocqlx_mv WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '2'
};

CREATE KEYSPACE gocqlx_mv WITH replication = {'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'datacenter1': '2'} AND durable_writes = true;
CREATE TABLE gocqlx_mv.mv_buildings (
name text PRIMARY KEY,
name text,
built int,
city text,
meters int
meters int,
PRIMARY KEY (name)
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys':'ALL','rows_per_partition':'ALL'}
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE';

AND speculative_retry = '99.0PERCENTILE'
AND paxos_grace_seconds = 864000
AND tombstone_gc = {'mode': 'timeout', 'propagation_delay_in_seconds': '3600'};
CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city AS
SELECT *
SELECT city, name, built, meters
FROM gocqlx_mv.mv_buildings
WHERE city IS NOT null
PRIMARY KEY (city, name)
WITH CLUSTERING ORDER BY (name ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys':'ALL','rows_per_partition':'ALL'}
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE';

AND speculative_retry = '99.0PERCENTILE'
AND paxos_grace_seconds = 864000
AND tombstone_gc = {'mode': 'timeout', 'propagation_delay_in_seconds': '3600'};
CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city2 AS
SELECT
city,
name,
meters
SELECT city, name, meters
FROM gocqlx_mv.mv_buildings
WHERE city IS NOT null
PRIMARY KEY (city, name)
WITH CLUSTERING ORDER BY (name ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys':'ALL','rows_per_partition':'ALL'}
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE';
AND speculative_retry = '99.0PERCENTILE'
AND paxos_grace_seconds = 864000
AND tombstone_gc = {'mode': 'timeout', 'propagation_delay_in_seconds': '3600'};
2 changes: 1 addition & 1 deletion testdata/recreate/secondary_index.cql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE KEYSPACE gocqlx_sec_idx WITH replication = {
'class': 'SimpleStrategy',
'class': 'NetworkTopologyStrategy',
'replication_factor': '2'
};

Expand Down
19 changes: 8 additions & 11 deletions testdata/recreate/secondary_index_golden.cql
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
CREATE KEYSPACE gocqlx_sec_idx WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '2'
};

CREATE KEYSPACE gocqlx_sec_idx WITH replication = {'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'datacenter1': '2'} AND durable_writes = true;
CREATE TABLE gocqlx_sec_idx.menus (
location text,
name text,
Expand All @@ -11,16 +7,17 @@ CREATE TABLE gocqlx_sec_idx.menus (
PRIMARY KEY (location, name)
) WITH CLUSTERING ORDER BY (name ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys':'ALL','rows_per_partition':'ALL'}
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE';

CREATE INDEX menus_name_idx ON gocqlx_sec_idx.menus ((location), name);
AND speculative_retry = '99.0PERCENTILE'
AND paxos_grace_seconds = 864000
AND tombstone_gc = {'mode': 'timeout', 'propagation_delay_in_seconds': '3600'};
CREATE INDEX menus_name_idx ON gocqlx_sec_idx.menus((location), name);
2 changes: 1 addition & 1 deletion testdata/recreate/table.cql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE KEYSPACE gocqlx_table WITH replication = {
'class': 'SimpleStrategy',
'class': 'NetworkTopologyStrategy',
'replication_factor': '2'
};

Expand Down
Loading

0 comments on commit eaad45e

Please sign in to comment.