Skip to content

Commit

Permalink
Add transaction tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Jun 27, 2024
1 parent e559b87 commit ce6150c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 22 deletions.
80 changes: 58 additions & 22 deletions java/integTest/src/test/java/glide/TransactionTestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import glide.api.models.commands.geospatial.GeoUnit;
import glide.api.models.commands.geospatial.GeospatialData;
import glide.api.models.commands.stream.StreamAddOptions;
import glide.api.models.commands.stream.StreamClaimOptions;
import glide.api.models.commands.stream.StreamGroupOptions;
import glide.api.models.commands.stream.StreamRange;
import glide.api.models.commands.stream.StreamRange.IdBound;
Expand Down Expand Up @@ -66,29 +67,37 @@ public interface TransactionBuilder extends Function<BaseTransaction<?>, Object[
/** Generate test samples for parametrized tests. Could be routed to random node. */
public static Stream<Arguments> getCommonTransactionBuilders() {
return Stream.of(
// Arguments.of(
// "Generic Commands", (TransactionBuilder)
// TransactionTestUtilities::genericCommands),
// Arguments.of(
// "String Commands", (TransactionBuilder)
// TransactionTestUtilities::stringCommands),
// Arguments.of("Hash Commands", (TransactionBuilder)
// TransactionTestUtilities::hashCommands),
// Arguments.of("List Commands", (TransactionBuilder)
// TransactionTestUtilities::listCommands),
// Arguments.of("Set Commands", (TransactionBuilder)
// TransactionTestUtilities::setCommands),
// Arguments.of(
// "Sorted Set Commands",
// (TransactionBuilder) TransactionTestUtilities::sortedSetCommands),
// Arguments.of(
// "HyperLogLog Commands",
// (TransactionBuilder)
// TransactionTestUtilities::hyperLogLogCommands),
Arguments.of(
"Generic Commands", (TransactionBuilder) TransactionTestUtilities::genericCommands),
Arguments.of(
"String Commands", (TransactionBuilder) TransactionTestUtilities::stringCommands),
Arguments.of("Hash Commands", (TransactionBuilder) TransactionTestUtilities::hashCommands),
Arguments.of("List Commands", (TransactionBuilder) TransactionTestUtilities::listCommands),
Arguments.of("Set Commands", (TransactionBuilder) TransactionTestUtilities::setCommands),
Arguments.of(
"Sorted Set Commands",
(TransactionBuilder) TransactionTestUtilities::sortedSetCommands),
Arguments.of(
"HyperLogLog Commands",
(TransactionBuilder) TransactionTestUtilities::hyperLogLogCommands),
Arguments.of(
"Stream Commands", (TransactionBuilder) TransactionTestUtilities::streamCommands),
Arguments.of(
"Connection Management Commands",
(TransactionBuilder) TransactionTestUtilities::connectionManagementCommands),
Arguments.of(
"Geospatial Commands",
(TransactionBuilder) TransactionTestUtilities::geospatialCommands),
Arguments.of(
"Bitmap Commands", (TransactionBuilder) TransactionTestUtilities::bitmapCommands));
"Stream Commands", (TransactionBuilder) TransactionTestUtilities::streamCommands));
// Arguments.of(
// "Connection Management Commands",
// (TransactionBuilder)
// TransactionTestUtilities::connectionManagementCommands),
// Arguments.of(
// "Geospatial Commands",
// (TransactionBuilder) TransactionTestUtilities::geospatialCommands),
// Arguments.of(
// "Bitmap Commands", (TransactionBuilder)
// TransactionTestUtilities::bitmapCommands));
}

/** Generate test samples for parametrized tests. Could be routed to primary nodes only. */
Expand Down Expand Up @@ -805,6 +814,22 @@ private static Object[] streamCommands(BaseTransaction<?> transaction) {
groupName1,
consumer1,
StreamReadGroupOptions.builder().count(2L).build())
.xclaim(streamKey1, groupName1, consumer1, 0L, new String[] {"0-1"})
.xclaim(
streamKey1,
groupName1,
consumer1,
0L,
new String[] {"0-3"},
StreamClaimOptions.builder().force().build())
.xclaimJustId(streamKey1, groupName1, consumer1, 0L, new String[] {"0-3"})
.xclaimJustId(
streamKey1,
groupName1,
consumer1,
0L,
new String[] {"0-4"},
StreamClaimOptions.builder().force().build())
.xpending(streamKey1, groupName1)
.xack(streamKey1, groupName1, new String[] {"0-3"})
.xpending(
Expand Down Expand Up @@ -850,6 +875,17 @@ private static Object[] streamCommands(BaseTransaction<?> transaction) {
Map.of(
streamKey1,
Map.of()), // xreadgroup(Map.of(streamKey1, ">"), groupName1, consumer1, options);
Map.of(), // xclaim(streamKey1, groupName1, consumer1, 0L, new String[] {"0-1"})
Map.of(
"0-3",
new String[] {
"field3", "value3"
}), // xclaim(streamKey1, groupName1, consumer1, 0L, {"0-3"}, options)
new String[] {
"0-3"
}, // xclaimJustId(streamKey1, groupName1, consumer1, 0L, new String[] {"0-3"})
new String
[0], // xclaimJustId(streamKey1, groupName1, consumer1, 0L, new String[] {"0-4"}, options)
new Object[] {
1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}}
}, // xpending(streamKey1, groupName1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void transactions_with_group_of_commands(String testName, TransactionBuil
Object[] expectedResult = builder.apply(transaction);

Object[] results = clusterClient.exec(transaction).get();
if (testName.equals("Stream Commands")) {
System.out.println(results);
}
assertDeepEquals(expectedResult, results);
}

Expand Down

0 comments on commit ce6150c

Please sign in to comment.