Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(itest): fix GraphQLTest.java #395

Merged
merged 38 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
db8af07
add testEnvironmentNodeListing
aali309 Mar 5, 2024
1304f9f
reopen PR
aali309 Apr 19, 2024
cbbb707
Test testOtherContainersFound
aali309 Apr 22, 2024
2da8984
testOtherContainersFound pass
aali309 Apr 29, 2024
0f762cc
testQueryForSpecificTargetWithSpecificFields pass
aali309 Apr 30, 2024
61d63c0
debug with Andrew
aali309 May 2, 2024
927df8b
port unit test from 2.4
andrewazores May 2, 2024
17c64ee
allow whitespace in label/annotation RHS (value)
andrewazores May 2, 2024
1d10ed3
if provided label/annotation selector expression cannot be parsed, th…
andrewazores May 2, 2024
771a347
mark class as QuarkusTest for unit test harness
andrewazores May 2, 2024
09fe5ae
do not try to apply annotations filters to discovery nodes without as…
andrewazores May 2, 2024
077727d
jackson (de)serialization config for easier/more lenient testing
andrewazores May 2, 2024
0b75f7c
troubleshooting test serialization issues
andrewazores May 2, 2024
2bbeeaa
test fixups
andrewazores May 2, 2024
3ec81f5
fix deleteRecording mutation bug
aali309 May 4, 2024
d368154
rebase and remove uni
aali309 May 7, 2024
13b7a69
testStartRecordingMutationOnSpecificTarget pass
aali309 May 7, 2024
d9e6e70
testArchiveMutation pass
aali309 May 8, 2024
d817b46
ActiveMuatation needs debug
aali309 Jun 6, 2024
cb6e113
testActiveRecordingMetadataMutation done
aali309 Jun 12, 2024
7685cf7
cleanup
aali309 Jun 12, 2024
ba48c5e
testArchivedRecordingMetadataMutation done
aali309 Jun 13, 2024
2edd2b7
testDeleteMutation done
aali309 Jun 13, 2024
a77f805
testQueryForSpecificTargetsByNames done
aali309 Jun 13, 2024
12daf90
testQueryForFilteredActiveRecordingsByNames done
aali309 Jun 14, 2024
629da85
shouldReturnArchivedRecordingsFilteredByNames completed
aali309 Jun 14, 2024
6b16019
testReplaceAlwaysOnStoppedRecording completed
aali309 Jun 14, 2024
7dd0411
testNodesHaveIds completed
aali309 Jun 14, 2024
91d7694
testNodesHaveIds cleanup
aali309 Jun 17, 2024
50497cb
testQueryforFilteredEnvironmentNodesByNames done
aali309 Jun 17, 2024
a3a53af
test with replace policy done
aali309 Jun 19, 2024
a575ec9
cleanup
aali309 Jun 20, 2024
3de88b0
more cleanup
aali309 Jun 20, 2024
797ce73
resolve issues
aali309 Jun 25, 2024
5672df4
resolve more issues
aali309 Jun 25, 2024
15918d7
specified imports explicitly
aali309 Jun 26, 2024
5df268c
Revert "specified imports explicitly"
aali309 Jun 26, 2024
0c41228
specified imports explicitly && remove webui commit
aali309 Jun 26, 2024
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
29 changes: 14 additions & 15 deletions src/main/java/io/cryostat/discovery/DiscoveryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,26 @@ public boolean equals(Object obj) {
&& Objects.equals(children, other.children);
}

@Override
public String toString() {
return "DiscoveryNode{"
+ "name='"
+ name
+ '\''
+ ", nodeType='"
+ nodeType
+ '\''
+ ", children="
+ children
+ '}';
}

@ApplicationScoped
static class Listener {

@Inject Logger logger;
@Inject EventBus bus;

// @Transactional
// @Blocking
// @ConsumeEvent(Target.TARGET_JVM_DISCOVERY)
// void onMessage(TargetDiscovery event) {
// switch (event.kind()) {
// case LOST:
// break;
// case FOUND:
// break;
// default:
// // no-op
// break;
// }
// }

@PrePersist
void prePersist(DiscoveryNode node) {}

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/io/cryostat/graphql/RootNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ public boolean test(DiscoveryNode t) {
Predicate<DiscoveryNode> matchesAnnotations =
n ->
annotations == null
|| annotations.stream()
.allMatch(
annotation ->
LabelSelectorMatcher.parse(annotation)
.test(
n.target.annotations
.merged()));
|| (n.target != null
&& annotations.stream()
.allMatch(
annotation ->
LabelSelectorMatcher.parse(
annotation)
.test(
n.target
.annotations
.merged())));

return List.of(
matchesId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LabelSelectorMatcher implements Predicate<Map<String, String>> {
// must loosely look like a k8s label (not strictly enforced here), right side must loosely look
// like a k8s label value, which may be empty. Allowed operators are "=", "==", "!=".
static final Pattern EQUALITY_PATTERN =
Pattern.compile("^(?<key>[^!=\\s]+)\\s*(?<op>=|==|!=)\\s*(?<value>[^!=\\s]*)$");
Pattern.compile("^(?<key>[^!=\\s]+)\\s*(?<op>=|==|!=)\\s*(?<value>[^!=]*)\\s*$");
andrewazores marked this conversation as resolved.
Show resolved Hide resolved

// ex. "environment in (production, qa)" or "tier NotIn (frontend, backend)". Tests if the given
// label has or does not have any of the specified values.
Expand Down Expand Up @@ -74,7 +74,9 @@ public static LabelSelectorMatcher parse(String clause) throws IllegalArgumentEx
return new LabelSelectorMatcher(List.of(matcher));
}
}
return new LabelSelectorMatcher();
throw new IllegalArgumentException(
String.format(
"No LabelSelectorMatcher case matched given expression: \"%s\"", clause));
}

private static LabelMatcher parseEqualities(String clause) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cryostat.graphql.matchers;

import java.util.Map;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

class LabelSelectorMatcherTest {

private static final Map<String, String> TEST_LABELS =
Map.of(
"foo", "bar",
"something", "else",
"my.prefixed/label", "expectedValue",
"env", "prod",
"present", "irrelevant");

@ParameterizedTest
@ValueSource(strings = {"this is not a valid expression"})
void testDoesNotMatchBadSyntax(String expr) {
Assertions.assertThrows(
IllegalArgumentException.class, () -> LabelSelectorMatcher.parse(expr));
}

@ParameterizedTest
@CsvSource({
"foo=bar, true",
"something=wrong, false",
"my.prefixed/label = expectedValue, true",
"env = Expected Value, false",
"env = prod, true",
"env = prod , true",
"env = dev, false",
"env = dev , false",
})
void testSingleEquality(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}

@ParameterizedTest
@CsvSource({
"foo==bar, true",
"something==wrong, false",
"my.prefixed/label == expectedValue, true"
})
void testDoubleEquality(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}

@ParameterizedTest
@CsvSource({
"foo!=bar, false",
"something!=wrong, true",
"my.prefixed/label != expectedValue, false"
})
void testInequality(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}

@ParameterizedTest
@CsvSource(
value = {
"foo in (bar, baz) : true",
"something In (else, orother) : true",
"env IN (stage,qa) : false",
},
delimiter = ':')
void testSetIn(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}

@ParameterizedTest
@CsvSource(
value = {
"foo notin (bar, baz) : false",
"something NotIn (orother, else, third) : false",
"env NOTIN (stage,qa) : true",
},
delimiter = ':')
void testSetNotIn(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}

@ParameterizedTest
@CsvSource({
"foo, true",
"something, true",
"my.prefixed/label, true",
"another/missing-label, false",
"present, true"
})
void testExists(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}

@ParameterizedTest
@CsvSource({"!foo, false", "!something, false", "!present, false"})
void testNotExists(String expr, boolean pass) {
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr);
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass));
}
}
Loading
Loading