StringInterningLayer { protected CompletableFuture<ResolverResult> create(@Nonnull FDBRecordContext context, @Nonnull final String toIntern, @Nullable final byte[] metadata) { return exists(context, toIntern) .thenCompose(present -> { if (present) { throw new RecordCoreException("value already exists in interning layer") .addLogInfo("value", toIntern); } return createMapping(context, toIntern, metadata); }); } StringInterningLayer(@Nonnull Subspace baseSubspace);  StringInterningLayer(@Nonnull Subspace baseSubspace, boolean isRootLevel); private  StringInterningLayer(@Nonnull Subspace mappingSubspace,
                                 @Nonnull Subspace reverseMappingSubspace,
                                 @Nonnull Subspace counterSubspace,
                                 boolean isRootLevel);   }
@Test void testCreate() { try (FDBRecordContext context = database.openContext()) { StringInterningLayer interningLayer = new StringInterningLayer(testSubspace); String toIntern = "some-string"; byte[] metadata = Tuple.from("some-metadata").pack(); ResolverResult interned = interningLayer.create(context, toIntern, metadata).join(); assertArrayEquals(interned.getMetadata(), metadata, "we see the metadata with the interned value"); Optional<ResolverResult> maybeRead = interningLayer.read(context, toIntern).join(); assertIsPresentWithValue("we read the value", maybeRead, interned); Optional<String> maybeReverseRead = interningLayer.readReverse(context, interned.getValue()).join(); assertIsPresentWithValue("the reverse lookup works", maybeReverseRead, toIntern); try { interningLayer.create(context, toIntern, null).join(); fail("should throw exception"); } catch (CompletionException ex) { assertThat(ex.getCause(), is(instanceOf(RecordCoreException.class))); assertThat(ex.getCause().getMessage(), containsString("value already exists in interning layer")); RecordCoreException cause = (RecordCoreException) ex.getCause(); assertThat("exception log info has the key", cause.getLogInfo(), hasEntry("value", toIntern)); } } }