Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.ByteBuffer;
import java.util.Base64;
import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

Expand Down Expand Up @@ -109,7 +110,7 @@ public void testJsonBinary() throws IOException
{
CdcEventBuilder eventBuilder = CdcEventBuilder.of(CdcEvent.Kind.INSERT, TEST_KS, TEST_TBL_BINARY);
eventBuilder.setPartitionKeys(listOf(Value.of(TEST_KS, "a", "int", TYPES.aInt().serialize(1))));
ByteBuffer randomBytes = ByteBuffer.wrap(RandomUtils.randomBytes(128));
ByteBuffer randomBytes = ByteBuffer.wrap(RandomUtils.randomBytes(new Random(), 128));
eventBuilder.setValueColumns(listOf(
Value.of(TEST_KS, "b", "blob", TYPES.blob().serialize(randomBytes)),
Value.of(TEST_KS, "c", "inet", TYPES.inet().serialize(InetAddress.getByName("127.0.0.1")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
Expand Down Expand Up @@ -107,14 +108,16 @@ public void testTtlDeletedAtByteAvroEncoding(CassandraVersion version)
.withColumn("c2", bridge.text());

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
for (int i = 0; i < tester.numRows; i++)
{
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows);
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows, random);
testRow.setTTL(ttlSeconds);
writer.accept(testRow, TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.cassandra.cdc;

import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
Expand Down Expand Up @@ -99,14 +100,16 @@ public void testBasicInsertAvroEncoding(CassandraVersion version)

// Capture CqlTable from the tester via the writer callback
AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
IntStream.range(0, tester.numRows)
.forEach(i -> writer.accept(CdcTester.newUniqueRow(tester.schema, rows), timestampMicros));
.forEach(i -> writer.accept(CdcTester.newUniqueRow(tester.schema, rows, random), timestampMicros));
})
.withCdcEventChecker((testRows, events) -> {
assertThat(events).hasSize(NUM_ROWS);
Expand Down Expand Up @@ -158,14 +161,16 @@ public void testCollectionTypesAvroEncoding(CassandraVersion version)
.withColumn("l", bridge.list(bridge.text()));

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
IntStream.range(0, tester.numRows)
.forEach(i -> writer.accept(CdcTester.newUniqueRow(tester.schema, rows), timestampMicros));
.forEach(i -> writer.accept(CdcTester.newUniqueRow(tester.schema, rows, random), timestampMicros));
})
.withCdcEventChecker((testRows, events) -> {
assertThat(events).hasSize(NUM_ROWS);
Expand Down Expand Up @@ -199,14 +204,16 @@ public void testAvroSerializeDeserializeRoundTrip(CassandraVersion version)
.withColumn("c2", bridge.text());

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
IntStream.range(0, tester.numRows)
.forEach(i -> writer.accept(CdcTester.newUniqueRow(tester.schema, rows), timestampMicros));
.forEach(i -> writer.accept(CdcTester.newUniqueRow(tester.schema, rows, random), timestampMicros));
})
.withCdcEventChecker((testRows, events) -> {
assertThat(events).hasSize(NUM_ROWS);
Expand Down Expand Up @@ -263,14 +270,16 @@ public void testDeleteEventAvroEncoding(CassandraVersion version)
.withColumn("c2", bridge.text());

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
for (int i = 0; i < tester.numRows; i++)
{
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows);
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows, random);
testRow = testRow.copy("c1", org.apache.cassandra.bridge.CdcBridge.UNSET_MARKER);
testRow = testRow.copy("c2", null);
writer.accept(testRow, TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()));
Expand Down Expand Up @@ -318,14 +327,16 @@ public void testMaxSupportedTtlAvroEncoding(CassandraVersion version)
.withColumn("c1", bridge.aInt());

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
for (int i = 0; i < tester.numRows; i++)
{
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows);
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows, random);
testRow.setTTL(largeTtl);
writer.accept(testRow, TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()));
}
Expand Down Expand Up @@ -387,14 +398,16 @@ public void testPartitionDeleteAvroEncoding(CassandraVersion version)
.withColumn("c1", bridge.aInt());

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
for (int i = 0; i < tester.numRows; i++)
{
TestSchema.TestRow testRow = newUniquePartitionDeletion(tester.schema, rows);
TestSchema.TestRow testRow = newUniquePartitionDeletion(tester.schema, rows, random);
writer.accept(testRow, TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()));
}
})
Expand Down Expand Up @@ -438,14 +451,16 @@ public void testMixedTtlAndNonTtlAvroEncoding(CassandraVersion version)
.withColumn("c1", bridge.aInt());

AtomicReference<CqlTable> tableRef = new AtomicReference<>();
Random random = new Random();
testWith(bridge, cdcBridge, commitLogDir, schemaBuilder)
.withNumRows(NUM_ROWS)
.withRandom(random)
.clearWriters()
.withWriter((tester, rows, writer) -> {
tableRef.set(tester.cqlTable);
for (int i = 0; i < tester.numRows; i++)
{
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows);
TestSchema.TestRow testRow = CdcTester.newUniqueRow(tester.schema, rows, random);
if (i % 2 == 0)
{
testRow.setTTL(ttlSeconds);
Expand Down
Loading
Loading