@Test void testUpdateForMissingKey() { byte[] metadata = Tuple.from("some-metadata").pack(); try (FDBRecordContext context = database.openContext()) { StringInterningLayer interningLayer = new StringInterningLayer(testSubspace); interningLayer.updateMetadata(context, "a-missing-key", metadata).join(); fail("should throw NoSuchElementException"); } catch (CompletionException ex) { assertThat(ex.getCause(), is(instanceOf(NoSuchElementException.class))); assertThat(ex.getCause(), hasMessageContaining("updateMetadata must reference key that already exists")); } }
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);   }