Open source a test case in `NestedSetCodecTest`.
@@ -77,7 +77,7 @@ public final class NestedSetCodecTest {
AtomicInteger reads = new AtomicInteger();
NestedSetStorageEndpoint endpoint =
new NestedSetStorageEndpoint() {
- InMemoryNestedSetStorageEndpoint delegate = new InMemoryNestedSetStorageEndpoint();
+ final InMemoryNestedSetStorageEndpoint delegate = new InMemoryNestedSetStorageEndpoint();
@Override
public ListenableFuture<Void> put(ByteString fingerprint, byte[] serializedBytes) {
@@ -415,6 +415,56 @@ public final class NestedSetCodecTest {
assertThat(result).isNotEqualTo(asyncResult.get());
}
+ @Test
+ public void writeFuturesWaitForTransitiveWrites() throws Exception {
+ NestedSetStorageEndpoint mockWriter = mock(NestedSetStorageEndpoint.class);
+ NestedSetStore store = new NestedSetStore(mockWriter);
+ SerializationContext mockSerializationContext = mock(SerializationContext.class);
+ when(mockSerializationContext.getNewMemoizingContext()).thenReturn(mockSerializationContext);
+
+ SettableFuture<Void> bottomReadFuture = SettableFuture.create();
+ SettableFuture<Void> middleReadFuture = SettableFuture.create();
+ SettableFuture<Void> topReadFuture = SettableFuture.create();
+ when(mockWriter.put(any(), any()))
+ .thenReturn(bottomReadFuture, middleReadFuture, topReadFuture);
+
+ NestedSet<String> bottom =
+ NestedSetBuilder.<String>stableOrder().add("bottom1").add("bottom2").build();
+ NestedSet<String> middle =
+ NestedSetBuilder.<String>stableOrder()
+ .add("middle1")
+ .add("middle2")
+ .addTransitive(bottom)
+ .build();
+ NestedSet<String> top =
+ NestedSetBuilder.<String>stableOrder()
+ .add("top1")
+ .add("top2")
+ .addTransitive(middle)
+ .build();
+
+ ListenableFuture<Void> bottomWriteFuture =
+ NestedSetCodecTestUtils.writeToStoreFuture(store, bottom, mockSerializationContext);
+ ListenableFuture<Void> middleWriteFuture =
+ NestedSetCodecTestUtils.writeToStoreFuture(store, middle, mockSerializationContext);
+ ListenableFuture<Void> topWriteFuture =
+ NestedSetCodecTestUtils.writeToStoreFuture(store, top, mockSerializationContext);
+ assertThat(bottomWriteFuture.isDone()).isFalse();
+ assertThat(middleWriteFuture.isDone()).isFalse();
+ assertThat(topWriteFuture.isDone()).isFalse();
+
+ topReadFuture.set(null);
+ middleReadFuture.set(null);
+ assertThat(bottomWriteFuture.isDone()).isFalse();
+ assertThat(middleWriteFuture.isDone()).isFalse();
+ assertThat(topWriteFuture.isDone()).isFalse();
+
+ bottomReadFuture.set(null);
+ assertThat(bottomWriteFuture.isDone()).isTrue();
+ assertThat(middleWriteFuture.isDone()).isTrue();
+ assertThat(topWriteFuture.isDone()).isTrue();
+ }
+
private static ObjectCodecs createCodecs(NestedSetStore store) {
return new ObjectCodecs(
AutoRegistry.get()
