use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable-hbase by googleapis.
the class TableAdapter method adapt.
/**
* adapt. This method adapts ColumnFamily to CreateTableRequest.
*
* @param desc a {@link HTableDescriptor} object.
* @param request a {@link CreateTableRequest}
*/
protected static void adapt(HTableDescriptor desc, CreateTableRequest request) {
if (request != null) {
for (HColumnDescriptor column : desc.getColumnFamilies()) {
String columnName = column.getNameAsString();
GCRule gcRule = buildGarbageCollectionRule(column);
if (gcRule == null) {
request.addFamily(columnName);
} else {
request.addFamily(columnName, gcRule);
}
}
}
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable by googleapis.
the class TableAdminExampleTest method testCreateMaxAgeRuleAndModifyAndPrintColumnFamily.
@Test
public void testCreateMaxAgeRuleAndModifyAndPrintColumnFamily() {
// Max age rule
tableAdmin.addFamilyWithMaxAgeRule();
DurationRule maxAgeCondition = GCRULES.maxAge(5, TimeUnit.DAYS);
boolean maxAgeRule = ruleCheck(maxAgeCondition);
assertTrue(maxAgeRule);
// Modifies cf1.
tableAdmin.modifyColumnFamilyRule();
GCRule modifiedRule = GCRULES.maxVersions(1);
boolean maxVersionRule = ruleCheck(modifiedRule);
assertTrue(maxVersionRule);
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable by googleapis.
the class TableAdminExampleTest method ruleCheck.
// TODO: add test for tableAdmin.listAllTables()
// TODO: add test for tableAdmin.getTableMeta()
// TODO: add test for tableAdmin.listColumnFamilies()
private boolean ruleCheck(GCRule condition) {
boolean found = false;
List<ColumnFamily> columnFamilies = adminClient.getTable(tableId).getColumnFamilies();
for (ColumnFamily columnFamily : columnFamilies) {
if (columnFamily.getGCRule().equals(condition)) {
found = true;
break;
}
}
return found;
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable by googleapis.
the class GCRulesTest method versions.
@Test
public void versions() {
VersionRule actual = GCRULES.maxVersions(10);
GcRule expected = buildVersionsRule(10);
assertNotNull(actual.getMaxVersions());
assertThat(actual.toProto()).isEqualTo(expected);
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable by googleapis.
the class GCRulesTest method unionOfIntersections.
@Test
public void unionOfIntersections() {
UnionRule actual = GCRULES.union().rule(GCRULES.intersection().rule(GCRULES.maxVersions(1)).rule(GCRULES.maxAge(Duration.ofSeconds(1)))).rule(GCRULES.intersection().rule(GCRULES.maxVersions(1)).rule(GCRULES.maxAge(Duration.ofSeconds(1))));
GcRule expected = GcRule.newBuilder().setUnion(Union.newBuilder().addRules(GcRule.newBuilder().setIntersection(Intersection.newBuilder().addRules(buildVersionsRule(1)).addRules(buildAgeRule(1, 0)))).addRules(GcRule.newBuilder().setIntersection(Intersection.newBuilder().addRules(buildVersionsRule(1)).addRules(buildAgeRule(1, 0))))).build();
assertEquals(2, actual.getRulesList().size());
assertThat(actual.toProto()).isEqualTo(expected);
}
Aggregations