Skip to content

fix(client): fix transactions mode being reversed #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
10 changes: 5 additions & 5 deletions src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public CompletableFuture<ClientWriteResponse> write(ClientWriteRequest request,
return writeTransactions(storeId, request, options);
}

private CompletableFuture<ClientWriteResponse> writeNonTransaction(
private CompletableFuture<ClientWriteResponse> writeTransactions(
String storeId, ClientWriteRequest request, ClientWriteOptions options) {

WriteRequest body = new WriteRequest();
Expand All @@ -390,7 +390,7 @@ private CompletableFuture<ClientWriteResponse> writeNonTransaction(
return call(() -> api.write(storeId, body, overrides)).thenApply(ClientWriteResponse::new);
}

private CompletableFuture<ClientWriteResponse> writeTransactions(
private CompletableFuture<ClientWriteResponse> writeNonTransaction(
String storeId, ClientWriteRequest request, ClientWriteOptions writeOptions) {

var options = writeOptions != null
Expand All @@ -412,10 +412,10 @@ private CompletableFuture<ClientWriteResponse> writeTransactions(

if (transactions.isEmpty()) {
var emptyTransaction = new ClientWriteRequest().writes(null).deletes(null);
return this.writeNonTransaction(storeId, emptyTransaction, writeOptions);
return this.writeTransactions(storeId, emptyTransaction, writeOptions);
}

var futureResponse = this.writeNonTransaction(storeId, transactions.get(0), options);
var futureResponse = this.writeTransactions(storeId, transactions.get(0), options);

for (int i = 1; i < transactions.size(); i++) {
final int index = i; // Must be final in this scope for closure.
Expand All @@ -424,7 +424,7 @@ private CompletableFuture<ClientWriteResponse> writeTransactions(
// 1. The first exception thrown in a failed completion. Other thenCompose() will not be evaluated.
// 2. The final successful ClientWriteResponse.
futureResponse = futureResponse.thenCompose(
_response -> this.writeNonTransaction(storeId, transactions.get(index), options));
_response -> this.writeTransactions(storeId, transactions.get(index), options));
}

return futureResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ public void writeTest_deletes() throws Exception {
}

@Test
public void writeTest_transactions() throws Exception {
public void writeTest_nonTransaction() throws Exception {
// Given
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
String writeTupleBody = String.format(
Expand Down Expand Up @@ -1142,7 +1142,7 @@ public void writeTest_transactions() throws Exception {
.writes(List.of(writeTuple, writeTuple, writeTuple, writeTuple, writeTuple))
.deletes(List.of(tuple, tuple, tuple, tuple, tuple));
ClientWriteOptions options =
new ClientWriteOptions().disableTransactions(false).transactionChunkSize(2);
new ClientWriteOptions().disableTransactions(true).transactionChunkSize(2);

// When
var response = fga.write(request, options).get();
Expand Down Expand Up @@ -1180,7 +1180,7 @@ public void writeTest_transactions() throws Exception {
}

@Test
public void writeTest_transactionsWithFailure() throws Exception {
public void writeTest_nonTransactionsWithFailure() {
// Given
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
String firstUser = "user:first";
Expand Down Expand Up @@ -1210,7 +1210,7 @@ public void writeTest_transactionsWithFailure() throws Exception {
.condition(DEFAULT_CONDITION))
.collect(Collectors.toList()));
ClientWriteOptions options =
new ClientWriteOptions().disableTransactions(false).transactionChunkSize(1);
new ClientWriteOptions().disableTransactions(true).transactionChunkSize(1);

// When
var execException = assertThrows(
Expand Down Expand Up @@ -1243,7 +1243,7 @@ public void writeTest_transactionsWithFailure() throws Exception {
}

@Test
public void writeTest_nonTransaction() throws Exception {
public void writeTest_transaction() throws Exception {
// Given
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
String writeTupleBody = String.format(
Expand Down Expand Up @@ -1272,7 +1272,7 @@ public void writeTest_nonTransaction() throws Exception {

// We expect transactionChunkSize will be ignored, and exactly one request will be sent.
ClientWriteOptions options =
new ClientWriteOptions().disableTransactions(true).transactionChunkSize(1);
new ClientWriteOptions().disableTransactions(false).transactionChunkSize(1);

// When
var response = fga.write(request, options).get();
Expand All @@ -1283,7 +1283,7 @@ public void writeTest_nonTransaction() throws Exception {
}

@Test
public void writeTest_nonTransactionsWithFailure() throws Exception {
public void writeTest_transactionWithFailure() {
// Given
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
String writeTupleBody = String.format(
Expand Down Expand Up @@ -1315,7 +1315,7 @@ public void writeTest_nonTransactionsWithFailure() throws Exception {

// We expect transactionChunkSize will be ignored, and exactly one request will be sent.
ClientWriteOptions options =
new ClientWriteOptions().disableTransactions(true).transactionChunkSize(1);
new ClientWriteOptions().disableTransactions(false).transactionChunkSize(1);

// When
var execException = assertThrows(
Expand Down