use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class WhileHandlerTest method shouldThrowExceptionWhenPredicateCannotAcceptInputType.
@Test
public void shouldThrowExceptionWhenPredicateCannotAcceptInputType() throws OperationException {
// Given
final Predicate predicate = new IsFalse();
final Object input = new EntitySeed();
final Conditional conditional = new Conditional(predicate);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final While operation = new While.Builder<>().input(input).conditional(conditional).operation(new GetElements()).build();
final WhileHandler handler = new WhileHandler();
// When / Then
try {
handler.doOperation(operation, context, store);
fail("Exception expected");
} catch (final OperationException e) {
assertTrue(e.getMessage().contains("The predicate '" + predicate.getClass().getSimpleName() + "' cannot accept an input of type '" + input.getClass().getSimpleName() + "'"));
}
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class WhileHandlerTest method shouldNotRepeatWhileConditionIsFalse.
@Test
public void shouldNotRepeatWhileConditionIsFalse() throws OperationException {
// Given
final EntitySeed input = mock(EntitySeed.class);
final int maxRepeats = 3;
final boolean condition = false;
final Operation delegate = mock(GetElements.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).condition(condition).operation(delegate).build();
final WhileHandler handler = new WhileHandler();
// When
handler.doOperation(operation, context, store);
// Then
verify(store, never()).execute((Output) delegate, context);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class WhileHandlerTest method shouldRepeatDelegateOperationUntilMaxRepeatsReached.
@Test
public void shouldRepeatDelegateOperationUntilMaxRepeatsReached() throws OperationException {
// Given
final List<EntitySeed> input = Collections.singletonList(mock(EntitySeed.class));
final int maxRepeats = 3;
final GetAdjacentIds delegate = mock(GetAdjacentIds.class);
final GetAdjacentIds delegateClone1 = mock(GetAdjacentIds.class);
final GetAdjacentIds delegateClone2 = mock(GetAdjacentIds.class);
final GetAdjacentIds delegateClone3 = mock(GetAdjacentIds.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
given(delegate.shallowClone()).willReturn(delegateClone1, delegateClone2, delegateClone3);
final CloseableIterable result1 = mock(CloseableIterable.class);
final CloseableIterable result2 = mock(CloseableIterable.class);
final CloseableIterable result3 = mock(CloseableIterable.class);
given(store.execute(delegateClone1, context)).willReturn(result1);
given(store.execute(delegateClone2, context)).willReturn(result2);
given(store.execute(delegateClone3, context)).willReturn(result3);
final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).operation(delegate).build();
final WhileHandler handler = new WhileHandler();
// When
final Object result = handler.doOperation(operation, context, store);
// Then
verify(delegateClone1, times(1)).getInput();
verify(delegateClone2, times(1)).getInput();
verify(delegateClone3, times(1)).getInput();
verify(store).execute((Output) delegateClone1, context);
verify(store).execute((Output) delegateClone2, context);
verify(store).execute((Output) delegateClone3, context);
assertSame(result3, result);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class GetJavaRDDOfElementsHandlerTest method checkGetCorrectElementsInJavaRDDForEntityId.
@Test
public void checkGetCorrectElementsInJavaRDDForEntityId() throws OperationException, IOException {
final Graph graph1 = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").build()).addSchema(getClass().getResourceAsStream("/schema/elements.json")).addSchema(getClass().getResourceAsStream("/schema/types.json")).addSchema(getClass().getResourceAsStream("/schema/serialisation.json")).storeProperties(PROPERTIES).build();
final List<Element> elements = new ArrayList<>();
for (int i = 0; i < 10; i++) {
final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).vertex("" + i).build();
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("" + i).dest("B").directed(false).property("count", 2).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("" + i).dest("C").directed(false).property("count", 4).build();
elements.add(edge1);
elements.add(edge2);
elements.add(entity);
}
final User user = new User();
graph1.execute(new AddElements.Builder().input(elements).build(), user);
// Create Hadoop configuration and serialise to a string
final Configuration configuration = new Configuration();
final String configurationString = AbstractGetRDDHandler.convertConfigurationToString(configuration);
// Check get correct edges for "1"
GetJavaRDDOfElements rddQuery = new GetJavaRDDOfElements.Builder().input(Collections.singleton(new EntitySeed("1"))).build();
rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
JavaRDD<Element> rdd = graph1.execute(rddQuery, user);
if (rdd == null) {
fail("No RDD returned");
}
final Set<Element> results = new HashSet<>(rdd.collect());
final Set<Element> expectedElements = new HashSet<>();
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).vertex("1").build();
final Edge edge1B = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("B").directed(false).property("count", 2).build();
final Edge edge1C = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("C").directed(false).property("count", 4).build();
expectedElements.add(entity1);
expectedElements.add(edge1B);
expectedElements.add(edge1C);
assertEquals(expectedElements, results);
// Check get correct edges for "1" when specify entities only
rddQuery = new GetJavaRDDOfElements.Builder().input(new EntitySeed("1")).view(new View.Builder().entity(ENTITY_GROUP).build()).build();
rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
rdd = graph1.execute(rddQuery, user);
if (rdd == null) {
fail("No RDD returned");
}
results.clear();
results.addAll(rdd.collect());
expectedElements.clear();
expectedElements.add(entity1);
assertEquals(expectedElements, results);
// Check get correct edges for "1" when specify edges only
rddQuery = new GetJavaRDDOfElements.Builder().input(new EntitySeed("1")).view(new View.Builder().edge(EDGE_GROUP).build()).build();
rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
rdd = graph1.execute(rddQuery, user);
if (rdd == null) {
fail("No RDD returned");
}
results.clear();
results.addAll(rdd.collect());
expectedElements.clear();
expectedElements.add(edge1B);
expectedElements.add(edge1C);
assertEquals(expectedElements, results);
// Check get correct edges for "1" and "5"
rddQuery = new GetJavaRDDOfElements.Builder().input(new EntitySeed("1"), new EntitySeed("5")).build();
rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
rdd = graph1.execute(rddQuery, user);
if (rdd == null) {
fail("No RDD returned");
}
results.clear();
results.addAll(rdd.collect());
final Entity entity5 = new Entity.Builder().group(TestGroups.ENTITY).vertex("5").build();
final Edge edge5B = new Edge.Builder().group(TestGroups.EDGE).source("5").dest("B").directed(false).property("count", 2).build();
final Edge edge5C = new Edge.Builder().group(TestGroups.EDGE).source("5").dest("C").directed(false).property("count", 4).build();
expectedElements.clear();
expectedElements.add(entity1);
expectedElements.add(edge1B);
expectedElements.add(edge1C);
expectedElements.add(entity5);
expectedElements.add(edge5B);
expectedElements.add(edge5C);
assertEquals(expectedElements, results);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AggregatorIteratorTest method test.
private void test(final AccumuloStore store) throws OperationException {
// Given
final Edge expectedResult = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COUNT, 13).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 1).build();
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 0).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 1).build();
final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 10).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
final User user = new User();
store.execute(new AddElements.Builder().input(edge1, edge2, edge3).build(), new Context(user));
final GetElements get = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).input(new EntitySeed("1")).build();
// When
final List<Element> results = Lists.newArrayList(store.execute(get, new Context(user)));
// Then
assertThat(results).hasSize(1);
final Edge aggregatedEdge = (Edge) results.get(0);
assertEquals(expectedResult, aggregatedEdge);
assertEquals(expectedResult.getProperties(), aggregatedEdge.getProperties());
}
Aggregations