in genie-web/src/integTest/java/com/netflix/genie/web/data/services/impl/jpa/JpaPersistenceServiceImplClustersIntegrationTest.java [578:676]
void testFindClustersMatchingCriterion() throws Exception {
// Create some clusters to test with
final Cluster cluster0 = this.createTestCluster(null, null, null);
final Cluster cluster1 = this.createTestCluster(null, null, null);
final Cluster cluster2 = this.createTestCluster(UUID.randomUUID().toString(), null, null);
// Create two commands with supersets of cluster1 tags so that we can test that resolution
final Set<String> cluster3Tags = Sets.newHashSet(cluster1.getMetadata().getTags());
cluster3Tags.add(UUID.randomUUID().toString());
cluster3Tags.add(UUID.randomUUID().toString());
final Cluster cluster3 = this.createTestCluster(null, cluster3Tags, null);
final Set<String> cluster4Tags = Sets.newHashSet(cluster1.getMetadata().getTags());
cluster4Tags.add(UUID.randomUUID().toString());
final Cluster cluster4 = this.createTestCluster(null, cluster4Tags, null);
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withId(cluster0.getId()).build(), true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(cluster0);
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withName(cluster2.getMetadata().getName()).build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(cluster2);
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withVersion(cluster1.getMetadata().getVersion()).build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(cluster1);
// This comes from the init.xml
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withStatus(ClusterStatus.OUT_OF_SERVICE.name()).build(),
false
)
)
.isEmpty();
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withTags(cluster1.getMetadata().getTags()).build(),
true
)
)
.hasSize(3)
.containsExactlyInAnyOrder(cluster1, cluster3, cluster4);
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withTags(cluster4.getMetadata().getTags()).build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(cluster4);
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder().withTags(Sets.newHashSet(UUID.randomUUID().toString())).build(),
true
)
)
.isEmpty();
// Everything
Assertions
.assertThat(
this.service.findClustersMatchingCriterion(
new Criterion.Builder()
.withId(cluster3.getId())
.withName(cluster3.getMetadata().getName())
.withVersion(cluster3.getMetadata().getVersion())
.withTags(cluster1.getMetadata().getTags()) // should be subset
.build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(cluster3);
}