in genie-web/src/integTest/java/com/netflix/genie/web/data/services/impl/jpa/JpaPersistenceServiceImplCommandsIntegrationTest.java [868:971]
void testFindCommandsMatchingCriterion() throws Exception {
// Create some commands to test with
final List<Criterion> clusterCriteria = List.of(
new Criterion.Builder().withName("prodCluster").build()
);
final Command command0 = this.createTestCommand(null, null, clusterCriteria);
final Command command1 = this.createTestCommand(null, null, clusterCriteria);
final Command command2 = this.createTestCommand(UUID.randomUUID().toString(), null, clusterCriteria);
// Create two commands with supersets of command1 tags so that we can test that resolution
final Set<String> command3Tags = new HashSet<>(command1.getMetadata().getTags());
command3Tags.add(UUID.randomUUID().toString());
command3Tags.add(UUID.randomUUID().toString());
final Command command3 = this.createTestCommand(null, command3Tags, clusterCriteria);
final Set<String> command4Tags = new HashSet<>(command1.getMetadata().getTags());
command4Tags.add(UUID.randomUUID().toString());
final Command command4 = this.createTestCommand(null, command4Tags, clusterCriteria);
// Create a command that has no cluster criteria to enforce matching doesn't work if there is no cluster
// criteria
final Command command5 = this.createTestCommand(null, null, null);
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withId(command0.getId()).build(), true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(command0);
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withName(command2.getMetadata().getName()).build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(command2);
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withVersion(command1.getMetadata().getVersion()).build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(command1);
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withTags(command1.getMetadata().getTags()).build(),
true
)
)
.hasSize(3)
.containsExactlyInAnyOrder(command1, command3, command4);
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withTags(command4.getMetadata().getTags()).build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(command4);
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withTags(Set.of(UUID.randomUUID().toString())).build(),
true
)
)
.isEmpty();
// Everything
Assertions
.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder()
.withId(command3.getId())
.withName(command3.getMetadata().getName())
.withVersion(command3.getMetadata().getVersion())
.withTags(command1.getMetadata().getTags()) // should be subset
.build(),
true
)
)
.hasSize(1)
.containsExactlyInAnyOrder(command3);
// Would match command5 if it had any cluster criteria
Assertions.assertThat(
this.service.findCommandsMatchingCriterion(
new Criterion.Builder().withId(command5.getId()).build(),
true
)
).isEmpty();
}