Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,86 @@ public void intersectionOfUnions() {
assertThat(actual.toProto()).isEqualTo(expected);
}

@Test
public void unionOfRules() {
GcRule protoGCRule =
GcRule.newBuilder()
.setUnion(
Union.newBuilder()
.addRules(buildAgeRule(10, 0))
.addRules(buildVersionsRule(1))
.addRules(buildAgeRule(20, 2)))
.build();

GCRules.GCRule modelGCRule =
GCRULES
.union()
.rule(GCRULES.maxAge(Duration.ofSeconds(10)))
.rule(GCRULES.maxVersions(1))
.rule(GCRULES.maxAge(Duration.ofSeconds(20, 2)));
assertThat(GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule);
}

@Test
public void intersectionWithFromProto() {
GcRule protoGCRule =
GcRule.newBuilder()
.setIntersection(
Intersection.newBuilder()
.addRules(buildAgeRule(10, 5))
.addRules(buildVersionsRule(1))
.addRules(buildVersionsRule(2)))
.build();

GCRules.GCRule modelGCRule =
GCRules.GCRULES
.intersection()
.rule(GCRULES.maxAge(org.threeten.bp.Duration.ofSeconds(10, 5)))
.rule(GCRULES.maxVersions(1))
.rule(GCRULES.maxVersions(2));
assertThat(GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule);
}

@Test
public void unionOfIntersectionFromProto() {
GcRule protoGCRule =
GcRule.newBuilder()
.setUnion(
Union.newBuilder()
.addRules(
GcRule.newBuilder()
.setIntersection(
Intersection.newBuilder()
.addRules(buildVersionsRule(10))
.addRules(buildAgeRule(2, 4))
.build())
.build())
.addRules(
GcRule.newBuilder()
.setIntersection(
Intersection.newBuilder()
.addRules(buildVersionsRule(1))
.addRules(buildAgeRule(1, 1))
.build())
.build()))
.build();

GCRules.GCRule modelGCRule =
GCRULES
.union()
.rule(
GCRULES
.intersection()
.rule(GCRULES.maxVersions(10))
.rule(GCRULES.maxAge(Duration.ofSeconds(2, 4))))
.rule(
GCRULES
.intersection()
.rule(GCRULES.maxVersions(1))
.rule(GCRULES.maxAge(Duration.ofSeconds(1, 1))));
assertThat(GCRules.GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule);
}

public static GcRule buildAgeRule(long seconds, int nanos) {
com.google.protobuf.Duration.Builder duartionBuilder =
com.google.protobuf.Duration.newBuilder();
Expand Down