Skip to content

Commit 21c1805

Browse files
authored
Merge pull request #60 from openfga/fix-flipped-transactions
fix(client): fix transactions mode being reversed
2 parents f142542 + 9c6bb02 commit 21c1805

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Diff for: src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public CompletableFuture<ClientWriteResponse> write(ClientWriteRequest request,
363363
return writeTransactions(storeId, request, options);
364364
}
365365

366-
private CompletableFuture<ClientWriteResponse> writeNonTransaction(
366+
private CompletableFuture<ClientWriteResponse> writeTransactions(
367367
String storeId, ClientWriteRequest request, ClientWriteOptions options) {
368368

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

393-
private CompletableFuture<ClientWriteResponse> writeTransactions(
393+
private CompletableFuture<ClientWriteResponse> writeNonTransaction(
394394
String storeId, ClientWriteRequest request, ClientWriteOptions writeOptions) {
395395

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

413413
if (transactions.isEmpty()) {
414414
var emptyTransaction = new ClientWriteRequest().writes(null).deletes(null);
415-
return this.writeNonTransaction(storeId, emptyTransaction, writeOptions);
415+
return this.writeTransactions(storeId, emptyTransaction, writeOptions);
416416
}
417417

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

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

430430
return futureResponse;

Diff for: src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ public void writeTest_deletes() throws Exception {
11061106
}
11071107

11081108
@Test
1109-
public void writeTest_transactions() throws Exception {
1109+
public void writeTest_nonTransaction() throws Exception {
11101110
// Given
11111111
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
11121112
String writeTupleBody = String.format(
@@ -1142,7 +1142,7 @@ public void writeTest_transactions() throws Exception {
11421142
.writes(List.of(writeTuple, writeTuple, writeTuple, writeTuple, writeTuple))
11431143
.deletes(List.of(tuple, tuple, tuple, tuple, tuple));
11441144
ClientWriteOptions options =
1145-
new ClientWriteOptions().disableTransactions(false).transactionChunkSize(2);
1145+
new ClientWriteOptions().disableTransactions(true).transactionChunkSize(2);
11461146

11471147
// When
11481148
var response = fga.write(request, options).get();
@@ -1180,7 +1180,7 @@ public void writeTest_transactions() throws Exception {
11801180
}
11811181

11821182
@Test
1183-
public void writeTest_transactionsWithFailure() throws Exception {
1183+
public void writeTest_nonTransactionsWithFailure() {
11841184
// Given
11851185
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
11861186
String firstUser = "user:first";
@@ -1210,7 +1210,7 @@ public void writeTest_transactionsWithFailure() throws Exception {
12101210
.condition(DEFAULT_CONDITION))
12111211
.collect(Collectors.toList()));
12121212
ClientWriteOptions options =
1213-
new ClientWriteOptions().disableTransactions(false).transactionChunkSize(1);
1213+
new ClientWriteOptions().disableTransactions(true).transactionChunkSize(1);
12141214

12151215
// When
12161216
var execException = assertThrows(
@@ -1243,7 +1243,7 @@ public void writeTest_transactionsWithFailure() throws Exception {
12431243
}
12441244

12451245
@Test
1246-
public void writeTest_nonTransaction() throws Exception {
1246+
public void writeTest_transaction() throws Exception {
12471247
// Given
12481248
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
12491249
String writeTupleBody = String.format(
@@ -1272,7 +1272,7 @@ public void writeTest_nonTransaction() throws Exception {
12721272

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

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

12851285
@Test
1286-
public void writeTest_nonTransactionsWithFailure() throws Exception {
1286+
public void writeTest_transactionWithFailure() {
12871287
// Given
12881288
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/write";
12891289
String writeTupleBody = String.format(
@@ -1315,7 +1315,7 @@ public void writeTest_nonTransactionsWithFailure() throws Exception {
13151315

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

13201320
// When
13211321
var execException = assertThrows(

0 commit comments

Comments
 (0)