Skip to content

Commit

Permalink
Gh-3200: Additional Federated Stores Tinkerpop tests (#3204)
Browse files Browse the repository at this point in the history
* additional testing and remove hard coded direction

* change graph
  • Loading branch information
cn337131 committed May 9, 2024
1 parent 49a8d38 commit 9d904ca
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ private List<ElementSeed> getElementSeeds(final Iterable<Object> ids) {
seeds.add(new EntitySeed(((Vertex) id).id()));
// Extract Edge ID
} else if (id instanceof Edge) {
seeds.add(new EdgeSeed(((Edge) id).outVertex().id(), ((Edge) id).inVertex().id(), true));
seeds.add(new EdgeSeed(((Edge) id).outVertex().id(), ((Edge) id).inVertex().id()));
// Extract source and destination from ID list
} else if (id instanceof Iterable) {
((Iterable<?>) id).forEach(edgeIdList::add);
Expand All @@ -912,7 +912,7 @@ private List<ElementSeed> getElementSeeds(final Iterable<Object> ids) {

// If found a list verify source and destination
if (edgeIdList.size() == 2) {
seeds.add(new EdgeSeed(edgeIdList.get(0), edgeIdList.get(1), true));
seeds.add(new EdgeSeed(edgeIdList.get(0), edgeIdList.get(1)));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.apache.tinkerpop.gremlin.structure.T;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.cache.CacheServiceLoader;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.tinkerpop.util.GafferPopFederatedTestUtil;

import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -76,6 +76,11 @@ public class GafferPopFederatedIT {
new SimpleEntry<>(T.label, PERSON_GROUP),
new SimpleEntry<>(NAME_PROPERTY, "person2Name"))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static final Map<Object, Object> EXPECTED_PERSON_3_VERTEX_MAP = Stream.of(
new SimpleEntry<>(T.id, "p3"),
new SimpleEntry<>(T.label, PERSON_GROUP),
new SimpleEntry<>(NAME_PROPERTY, "person3Name"))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

@BeforeEach
public void setUp() throws Exception {
Expand All @@ -96,7 +101,7 @@ void shouldConstructFederatedGafferPopGraph() {
// Then
assertThat(variables).contains(
entry("userId", USER_ID),
entry("dataAuths", new String[]{AUTH_1, AUTH_2}));
entry("dataAuths", new String[] {AUTH_1, AUTH_2}));
}

@Test
Expand Down Expand Up @@ -212,15 +217,13 @@ void shouldGroupVerticesByLabelAndProvideCount() {
}

@Test
@Disabled("This does not currently work with federation")
void shouldGetEdgesById() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();

// When
List<Edge> result = g.E("[p1, s1]", "[p3, s1]").toList();

// Then
assertThat(result)
.extracting(item -> item.id().toString())
.containsExactly("[p1, s1]", "[p3, s1]");
Expand Down Expand Up @@ -274,4 +277,111 @@ void shouldTraverseEdgesFromVertexAndReturnNames() {
.containsExactly(EXPECTED_PERSON_2_VERTEX_MAP.get("name"),
EXPECTED_SOFTWARE_1_VERTEX_MAP.get("name"));
}

@Test
void shouldReturnVerticesByLabelFromSpecificGraph() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();
final List<String> graphOptions = Arrays.asList("gaffer.federatedstore.operation.graphIds:graphA");

// When
List<Map<Object, Object>> result = g.with(GafferPopGraphVariables.OP_OPTIONS, graphOptions).V()
.hasLabel(PERSON_GROUP)
.elementMap().toList();

// Then
assertThat(result)
.containsExactlyInAnyOrder(EXPECTED_PERSON_1_VERTEX_MAP, EXPECTED_PERSON_2_VERTEX_MAP,
EXPECTED_PERSON_3_VERTEX_MAP);
}

@Test
void shouldReturnFilteredVerticesFromSpecificGraph() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();
final List<String> graphOptions = Arrays.asList("gaffer.federatedstore.operation.graphIds:graphA");

// When
List<Object> result = g.with(GafferPopGraphVariables.OP_OPTIONS, graphOptions).V()
.outE(CREATED_EDGE_GROUP).has(WEIGHT_PROPERTY, P.gt(0.2))
.values(WEIGHT_PROPERTY)
.toList();

// Then
assertThat(result)
.containsExactly(0.4);
}

@Test
void shouldGroupVerticesByLabelAndProvideCountFromSpecificGraph() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();
final List<String> graphOptions = Arrays.asList("gaffer.federatedstore.operation.graphIds:graphB");

// When
List<Map<Object, Long>> result = g.with(GafferPopGraphVariables.OP_OPTIONS, graphOptions).V().groupCount()
.by(T.label).toList();

assertThat(result)
.first()
.hasFieldOrPropertyWithValue(PERSON_GROUP, 1L)
.hasFieldOrPropertyWithValue(SOFTWARE_GROUP, 1L);
}

@Test
void shouldGetEdgesByIdFromSpecificGraph() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();
final List<String> graphOptions = Arrays.asList("gaffer.federatedstore.operation.graphIds:graphB");

// When
List<Edge> result = g.with(GafferPopGraphVariables.OP_OPTIONS, graphOptions).E("[p4, s2]").toList();

assertThat(result)
.extracting(item -> item.id().toString())
.containsExactly("[p4, s2]");

assertThat(result)
.extracting(item -> item.label())
.containsExactly(CREATED_EDGE_GROUP);
}

@Test
void shouldGetOutgoingEdgesFromSpecificGraph() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();
final List<String> graphOptions = Arrays.asList("gaffer.federatedstore.operation.graphIds:graphB");

// When
List<Edge> result = g.with(GafferPopGraphVariables.OP_OPTIONS, graphOptions).V("p4").outE().toList();

// Then
assertThat(result)
.extracting(item -> item.id().toString())
.containsExactly("[p4, s2]");

assertThat(result)
.extracting(item -> item.label())
.containsExactly(CREATED_EDGE_GROUP);
}

@Test
void shouldGetIncomingEdgesFromSpecificGraph() {
// Given
GraphTraversalSource g = gafferPopGraph.traversal();
final List<String> graphOptions = Arrays.asList("gaffer.federatedstore.operation.graphIds:graphA");

// When
List<Edge> result = g.with(GafferPopGraphVariables.OP_OPTIONS, graphOptions).V(VERTEX_PERSON_1).outE()
.toList();

// Then
assertThat(result)
.extracting(item -> item.id().toString())
.containsExactlyInAnyOrder("[p1, p2]", "[p1, s1]");

assertThat(result)
.extracting(item -> item.label())
.containsExactlyInAnyOrder(CREATED_EDGE_GROUP, "knows");
}
}

0 comments on commit 9d904ca

Please sign in to comment.