ColumnDescriptorAdapter { public ColumnFamily adapt(HColumnDescriptor columnDescriptor) { throwIfRequestingUnknownFeatures(columnDescriptor); throwIfRequestingUnsupportedFeatures(columnDescriptor); ColumnFamily.Builder resultBuilder = ColumnFamily.newBuilder(); GCRule gcRule = buildGarbageCollectionRule(columnDescriptor); if (gcRule != null) { resultBuilder.setGcRule(gcRule.toProto()); } return resultBuilder.build(); }  static List<String> getUnknownFeatures(HColumnDescriptor columnDescriptor); static Map<String, String> getUnsupportedFeatures(HColumnDescriptor columnDescriptor); static void throwIfRequestingUnknownFeatures(HColumnDescriptor columnDescriptor); static void throwIfRequestingUnsupportedFeatures(HColumnDescriptor columnDescriptor); static GCRule buildGarbageCollectionRule(HColumnDescriptor columnDescriptor); ColumnFamily adapt(HColumnDescriptor columnDescriptor); HColumnDescriptor adapt(
      com.google.cloud.bigtable.admin.v2.models.ColumnFamily columnFamily); static final ColumnDescriptorAdapter INSTANCE; static final Set<String> SUPPORTED_OPTION_KEYS; static final Set<String> IGNORED_OPTION_KEYS; static final Map<String, String> SUPPORTED_OPTION_VALUES; }
@Test public void exceptionIsThrownOnUnknownOptions() { descriptor.setConfiguration("UnknownConfigurationKey", "UnknownConfigurationValue"); expectedException.expectMessage("Unknown configuration options"); expectedException.expectMessage("UnknownConfigurationKey"); expectedException.expect(UnsupportedOperationException.class); adapter.adapt(descriptor); }
@Test public void exceptionIsThrownWhenAUnsupportedValueIsSet() { Set<Map.Entry<String, String>> ignoredEntryes = ColumnDescriptorAdapter.SUPPORTED_OPTION_VALUES.entrySet(); for (Map.Entry<String, String> entry : ignoredEntryes) { String invalidValue = entry.getValue() + "_invalid"; descriptor.setConfiguration(entry.getKey(), invalidValue); expectedException.expectMessage(entry.getKey()); expectedException.expectMessage(invalidValue); } expectedException.expectMessage("Unsupported configuration options"); expectedException.expect(UnsupportedOperationException.class); adapter.adapt(descriptor); }
@Test public void ignoredOptionsAreIgnored() { descriptor.setCompressionType(Compression.Algorithm.LZ4); descriptor.setCompactionCompressionType(Compression.Algorithm.LZ4); descriptor.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF); descriptor.setBlockCacheEnabled(false); descriptor.setCacheDataOnWrite(true); descriptor.setCacheDataInL1(true); descriptor.setEvictBlocksOnClose(false); descriptor.setBloomFilterType(BloomType.ROW); descriptor.setPrefetchBlocksOnOpen(true); descriptor.setBlocksize(16 * 1024); descriptor.setScope(1); descriptor.setInMemory(true); ColumnFamily.Builder result = adapter.adapt(descriptor).toBuilder().clearGcRule(); Assert.assertArrayEquals(new byte[0], result.build().toByteArray()); }
@Test public void ttlIsPreservedInGcRule() { int ttl = 86400; descriptor.setTimeToLive(ttl); ColumnFamily result = adapter.adapt(descriptor); GCRules.GCRule expected = GCRULES.union().rule(GCRULES.maxAge(Duration.ofSeconds(ttl))).rule(GCRULES.maxVersions(1)); Assert.assertEquals(expected.toProto(), result.getGcRule()); }
@Test public void ttlIsPreservedInColumnFamily() { GCRules.GCRule expected = GCRULES .union() .rule(GCRULES.maxAge(Duration.ofSeconds(86400))) .rule(GCRULES.maxVersions(1)); HColumnDescriptor descriptor = adapter.adapt(columnFamily(expected)); Assert.assertEquals(1, descriptor.getMaxVersions()); Assert.assertEquals(86400, descriptor.getTimeToLive()); }
@Test public void maxVersionsIsPreservedInGcExpression() { descriptor.setMaxVersions(10); ColumnFamily result = adapter.adapt(descriptor); GCRules.GCRule expected = GCRULES.maxVersions(10); Assert.assertEquals(expected.toProto(), result.getGcRule()); }
@Test public void maxVersionsIsPreservedInColumnFamily() { GCRules.GCRule expected = GCRULES.maxVersions(10); HColumnDescriptor descriptor = adapter.adapt(columnFamily(expected)); Assert.assertEquals(10, descriptor.getMaxVersions()); }
@Test public void minMaxTtlInDescriptor() { descriptor.setMaxVersions(20); descriptor.setMinVersions(10); descriptor.setTimeToLive(86400); ColumnFamily result = adapter.adapt(descriptor); Assert.assertEquals(minMaxRule(10, 86400, 20).toProto(), result.getGcRule()); }
@Test public void minMaxTtlInColumnFamily() { HColumnDescriptor descriptor = adapter.adapt(columnFamily(minMaxRule(10, 86400, 20))); Assert.assertEquals(20, descriptor.getMaxVersions()); Assert.assertEquals(10, descriptor.getMinVersions()); Assert.assertEquals(86400, descriptor.getTimeToLive()); }
@Test public void minVersionsMustBeLessThanMaxversion() { descriptor.setMaxVersions(10); descriptor.setMinVersions(20); expectedException.expect(IllegalStateException.class); adapter.adapt(descriptor); }
@Test public void minVersionsMustBeLessThanMaxversionInExpression() { expectedException.expect(IllegalArgumentException.class); adapter.adapt(columnFamily(minMaxRule(20, 86400, 10))); }
@Test public void testGCruleMaxVersion() { int ttl = 100; descriptor.setTimeToLive(ttl); descriptor.setMaxVersions(Integer.MAX_VALUE); ColumnFamily result = adapter.adapt(descriptor); GCRule expected = GCRULES.maxAge(Duration.ofSeconds(ttl)); Assert.assertEquals(expected.toProto(), result.getGcRule()); }
@Test public void testAdaptWithColumnFamilyForMaxAge() { int ttl = 86400; GCRule maxAgeGCRule = GCRULES.maxAge(Duration.ofSeconds(ttl)); HColumnDescriptor actual = adapter.adapt(columnFamily(maxAgeGCRule)); Assert.assertEquals(ttl, actual.getTimeToLive()); }