Search in sources :

Example 11 with GCRule

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);
            }
        }
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ByteString(com.google.protobuf.ByteString)

Example 12 with 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);
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) Test(org.junit.Test)

Example 13 with GCRule

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;
}
Also used : ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily)

Example 14 with GCRule

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);
}
Also used : GcRule(com.google.bigtable.admin.v2.GcRule) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) Test(org.junit.Test)

Example 15 with GCRule

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);
}
Also used : GcRule(com.google.bigtable.admin.v2.GcRule) UnionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 GCRule (com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)9 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)6 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)4 GcRule (com.google.bigtable.admin.v2.GcRule)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)3 Table (com.google.bigtable.admin.v2.Table)2 DurationRule (com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule)2 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)1 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)1 GCRules (com.google.cloud.bigtable.admin.v2.models.GCRules)1 IntersectionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule)1 UnionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule)1 VersionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule)1 ByteString (com.google.protobuf.ByteString)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1