@Test void testUpdateMetadata() { byte[] oldMetadata = Tuple.from("old-metadata").pack(); byte[] newMetadata = Tuple.from("new-metadata").pack(); StringInterningLayer interningLayer; ResolverResult initial; ResolverResult updated; final String key = "update-metadata"; try (FDBRecordContext context = database.openContext()) { interningLayer = new StringInterningLayer(testSubspace); initial = interningLayer.create(context, key, oldMetadata).join(); interningLayer.updateMetadata(context, key, newMetadata).join(); updated = interningLayer.read(context, key).join().orElseThrow(() -> new AssertionError("should be present")); assertThat("we see the new metadata", updated, is(new ResolverResult(initial.getValue(), newMetadata))); context.commit(); } try (FDBRecordContext context = database.openContext()) { ResolverResult newTransactionRead = interningLayer.read(context, key).join().orElseThrow(() -> new AssertionError("should be present")); assertThat("we see the committed metadata in a new transaction", newTransactionRead, is(updated)); } }
protected CompletableFuture<Void> updateMetadata(@Nonnull final FDBRecordContext context, @Nonnull final String key, @Nullable final byte[] metadata) { return read(context, key).thenApply(maybeRead -> maybeRead.map(read -> new ResolverResult(read.getValue(), metadata)) .orElseThrow(() -> new NoSuchElementException("updateMetadata must reference key that already exists"))) .thenAccept(newResult -> context.ensureActive().set(mappingSubspace.pack(key), serializeValue(newResult))); }
StringInterningLayer { protected CompletableFuture<Void> updateMetadata(@Nonnull final FDBRecordContext context, @Nonnull final String key, @Nullable final byte[] metadata) { return read(context, key).thenApply(maybeRead -> maybeRead.map(read -> new ResolverResult(read.getValue(), metadata)) .orElseThrow(() -> new NoSuchElementException("updateMetadata must reference key that already exists"))) .thenAccept(newResult -> context.ensureActive().set(mappingSubspace.pack(key), serializeValue(newResult))); } }
StringInterningLayer { protected CompletableFuture<Void> updateMetadata(@Nonnull final FDBRecordContext context, @Nonnull final String key, @Nullable final byte[] metadata) { return read(context, key).thenApply(maybeRead -> maybeRead.map(read -> new ResolverResult(read.getValue(), metadata)) .orElseThrow(() -> new NoSuchElementException("updateMetadata must reference key that already exists"))) .thenAccept(newResult -> context.ensureActive().set(mappingSubspace.pack(key), serializeValue(newResult))); } StringInterningLayer(@Nonnull Subspace baseSubspace);  StringInterningLayer(@Nonnull Subspace baseSubspace, boolean isRootLevel); private  StringInterningLayer(@Nonnull Subspace mappingSubspace,
                                 @Nonnull Subspace reverseMappingSubspace,
                                 @Nonnull Subspace counterSubspace,
                                 boolean isRootLevel); }
StringInterningLayer { protected CompletableFuture<Void> updateMetadata(@Nonnull final FDBRecordContext context, @Nonnull final String key, @Nullable final byte[] metadata) { return read(context, key).thenApply(maybeRead -> maybeRead.map(read -> new ResolverResult(read.getValue(), metadata)) .orElseThrow(() -> new NoSuchElementException("updateMetadata must reference key that already exists"))) .thenAccept(newResult -> context.ensureActive().set(mappingSubspace.pack(key), serializeValue(newResult))); } StringInterningLayer(@Nonnull Subspace baseSubspace);  StringInterningLayer(@Nonnull Subspace baseSubspace, boolean isRootLevel); private  StringInterningLayer(@Nonnull Subspace mappingSubspace,
                                 @Nonnull Subspace reverseMappingSubspace,
                                 @Nonnull Subspace counterSubspace,
                                 boolean isRootLevel);  }
StringInterningLayer { protected CompletableFuture<Void> updateMetadata(@Nonnull final FDBRecordContext context, @Nonnull final String key, @Nullable final byte[] metadata) { return read(context, key).thenApply(maybeRead -> maybeRead.map(read -> new ResolverResult(read.getValue(), metadata)) .orElseThrow(() -> new NoSuchElementException("updateMetadata must reference key that already exists"))) .thenAccept(newResult -> context.ensureActive().set(mappingSubspace.pack(key), serializeValue(newResult))); } StringInterningLayer(@Nonnull Subspace baseSubspace);  StringInterningLayer(@Nonnull Subspace baseSubspace, boolean isRootLevel); private  StringInterningLayer(@Nonnull Subspace mappingSubspace,
                                 @Nonnull Subspace reverseMappingSubspace,
                                 @Nonnull Subspace counterSubspace,
                                 boolean isRootLevel);   }