DocumentTranslator { public List<Document> translate(final Table table, final List<Document> inDocuments) { ImmutableList.Builder<Document> docListBuilder = ImmutableList.builder(); for (Document document : inDocuments) { docListBuilder.add(translate(table, document)); } return docListBuilder.build(); } @Inject  DocumentTranslator(TranslatorConfig translatorConfig); List<Document> translate(final Table table, final List<Document> inDocuments); Document translate(final Table table, final Document inDocument); Document translateBack(final Document inDocument); @VisibleForTesting String generateScalableKey(String id); String rawStorageIdFromDocumentId(Table table, String id);  }
@Test public void testTranslationWithNullRawKeyVersion() { TranslatorConfig hbaseConfig = new TranslatorConfig(); hbaseConfig.setRawKeyVersion(null); DocumentTranslator translator = new DocumentTranslator(hbaseConfig); Table table = new Table(); table.setName(UUID.randomUUID() .toString()); Document document = new Document(); document.setId(UUID.randomUUID() .toString()); document.setTimestamp(System.currentTimeMillis()); document.setData(mapper.createObjectNode() .put("name", NAME)); Document translatedDocument = translator.translate(table, document); assertEquals(translatedDocument.getId(), document.getId()); assertNotNull(translatedDocument.getMetadata()); assertEquals(translatedDocument.getMetadata() .getId(), document.getId()); assertEquals(translatedDocument.getMetadata() .getRawStorageId(), document.getId() + ":" + table.getName()); }
@Test public void testTranslationWithRawKeyVersion1() { DocumentTranslator translator = new DocumentTranslator(TestUtils.createTranslatorConfigWithRawKeyV1()); Table table = new Table(); table.setName(UUID.randomUUID() .toString()); Document document = new Document(); document.setId(UUID.randomUUID() .toString()); document.setTimestamp(System.currentTimeMillis()); document.setData(mapper.createObjectNode() .put("name", NAME)); Document translatedDocument = translator.translate(table, document); assertEquals(translatedDocument.getId(), document.getId()); assertNotNull(translatedDocument.getMetadata()); assertEquals(translatedDocument.getMetadata() .getId(), document.getId()); assertEquals(translatedDocument.getMetadata() .getRawStorageId(), document.getId() + ":" + table.getName()); }
@Test public void testTranslationWithRawKeyVersion2() { DocumentTranslator translator = new DocumentTranslator(TestUtils.createTranslatorConfigWithRawKeyV2()); Table table = new Table(); table.setName(UUID.randomUUID() .toString()); Document document = new Document(); document.setId(UUID.randomUUID() .toString()); document.setTimestamp(System.currentTimeMillis()); document.setData(mapper.createObjectNode() .put("name", NAME)); Document translatedDocument = translator.translate(table, document); assertNotNull(translatedDocument.getMetadata()); assertEquals(translatedDocument.getId(), translatedDocument.getMetadata() .getRawStorageId()); assertEquals(translatedDocument.getMetadata() .getId(), document.getId()); assertTrue(translatedDocument.getMetadata() .getRawStorageId() .endsWith(Constants.RAW_KEY_VERSION_TO_SUFFIX_MAP.get("2.0"))); }