|
36 | 36 | import com.apple.foundationdb.record.test.TestKeySpace; |
37 | 37 | import com.apple.foundationdb.record.test.TestKeySpacePathManagerExtension; |
38 | 38 | import com.apple.foundationdb.subspace.Subspace; |
| 39 | +import com.apple.foundationdb.test.FDBTestEnvironment; |
39 | 40 | import com.apple.foundationdb.tuple.Tuple; |
40 | 41 | import com.apple.test.BooleanSource; |
41 | 42 | import com.apple.test.Tags; |
|
54 | 55 |
|
55 | 56 | import javax.annotation.Nonnull; |
56 | 57 | import java.io.IOException; |
| 58 | +import java.util.UUID; |
57 | 59 | import java.util.concurrent.CompletableFuture; |
58 | 60 | import java.util.concurrent.ExecutionException; |
59 | 61 | import java.util.concurrent.TimeUnit; |
|
66 | 68 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
67 | 69 | import static org.hamcrest.Matchers.lessThan; |
68 | 70 | import static org.hamcrest.Matchers.lessThanOrEqualTo; |
| 71 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
69 | 72 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
70 | 73 | import static org.junit.jupiter.api.Assertions.assertEquals; |
71 | 74 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -240,7 +243,7 @@ void testJoinNowOnNonCompletedFuture(BlockingInAsyncDetection behavior) { |
240 | 243 | if (behavior.throwExceptionOnBlocking()) { |
241 | 244 | assertThrows(BlockingInAsyncException.class, () -> database.joinNow(new CompletableFuture<>())); |
242 | 245 | } else { |
243 | | - FDBDatabase database2 = factory.getDatabase(); |
| 246 | + FDBDatabase database2 = factory.getDatabase(database.getClusterFile()); |
244 | 247 | TestHelpers.assertLogs(FDBDatabase.class, FDBDatabase.BLOCKING_FOR_FUTURE_MESSAGE, () -> { |
245 | 248 | long val = database2.joinNow(MoreAsyncUtil.delayedFuture(100, TimeUnit.MILLISECONDS, database2.getScheduledExecutor()) |
246 | 249 | .thenApply(vignore -> 1066L)); |
@@ -494,4 +497,31 @@ void cannotChangeAPIVersionAfterInit() { |
494 | 497 | assertEquals(initApiVersion, database.getAPIVersion()); |
495 | 498 | } |
496 | 499 | } |
| 500 | + |
| 501 | + @Test |
| 502 | + void canAccessMultipleClusters() { |
| 503 | + FDBTestEnvironment.assumeClusterCount(2); |
| 504 | + final FDBDatabase database0 = dbExtension.getDatabase(0); |
| 505 | + final FDBDatabase database1 = dbExtension.getDatabase(1); |
| 506 | + final byte[] key = Tuple.from(UUID.randomUUID()).pack(); |
| 507 | + final byte[] value0 = Tuple.from("cluster0").pack(); |
| 508 | + final byte[] value1 = Tuple.from("cluster1").pack(); |
| 509 | + try (FDBRecordContext context0 = database0.openContext()) { |
| 510 | + context0.ensureActive().set(key, value0); |
| 511 | + context0.commit(); |
| 512 | + } |
| 513 | + try (FDBRecordContext context1 = database1.openContext()) { |
| 514 | + assertNull(context1.ensureActive().get(key).join()); |
| 515 | + context1.ensureActive().set(key, value1); |
| 516 | + context1.commit(); |
| 517 | + } |
| 518 | + try (FDBRecordContext context0 = database0.openContext()) { |
| 519 | + assertArrayEquals(value0, context0.ensureActive().get(key).join()); |
| 520 | + context0.commit(); |
| 521 | + } |
| 522 | + try (FDBRecordContext context1 = database1.openContext()) { |
| 523 | + assertArrayEquals(value1, context1.ensureActive().get(key).join()); |
| 524 | + context1.commit(); |
| 525 | + } |
| 526 | + } |
497 | 527 | } |
0 commit comments