use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldNotSetGraphViewOnOperationWhenOperationViewIsNotNull.
@Test
public void shouldNotSetGraphViewOnOperationWhenOperationViewIsNotNull() throws OperationException {
// Given
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
final View opView = mock(View.class);
final View view = mock(View.class);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).store(store).build();
final Integer expectedResult = 5;
given(operation.getView()).willReturn(opView);
final OperationChain<Integer> opChain = mock(OperationChain.class);
final OperationChain<Integer> clonedOpChain = mock(OperationChain.class);
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(store.execute(clonedOpChain, clonedContext)).willReturn(expectedResult);
// When
Integer result = graph.execute(opChain, context);
// Then
assertEquals(expectedResult, result);
verify(store).execute(clonedOpChain, clonedContext);
verify(operation, Mockito.never()).setView(view);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldThrowExceptionWithNullSchema.
@Test
public void shouldThrowExceptionWithNullSchema() {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
// When / Then
try {
new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(storeProperties).build();
} catch (final SchemaException e) {
assertTrue(e.getMessage().contains("Schema is missing"));
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method preserveAllEntitiesIfNoEntitiesInSchema.
@Test
public void preserveAllEntitiesIfNoEntitiesInSchema() throws OperationException {
final Schema twoEdgesNoEntities = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).type("vertex", new TypeDefinition.Builder().clazz(String.class).build()).edge("firstEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).edge("secondEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).build();
final Store store = mock(Store.class);
final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> capturedContext = ArgumentCaptor.forClass(Context.class);
given(store.getSchema()).willReturn(twoEdgesNoEntities);
given(store.getOriginalSchema()).willReturn(twoEdgesNoEntities);
given(store.getProperties()).willReturn(mock(StoreProperties.class));
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(twoEdgesNoEntities).build();
final ElementFilter filter = mock(ElementFilter.class);
final GlobalViewElementDefinition globalEdgeAggregate = new GlobalViewElementDefinition.Builder().postAggregationFilter(filter).build();
final View view = new View.Builder().allEntities(true).build();
operation = new GetElements.Builder().view(view).build();
opChain = new OperationChain.Builder().first(operation).build();
graph.execute(opChain, context);
Mockito.verify(store, Mockito.times(1)).execute(capturedOperation.capture(), capturedContext.capture());
assertEquals(1, capturedOperation.getAllValues().size());
final OperationChain transformedOpChain = capturedOperation.getAllValues().get(0);
assertEquals(1, transformedOpChain.getOperations().size());
assertEquals(GetElements.class, transformedOpChain.getOperations().get(0).getClass());
final View mergedView = ((GetElements) transformedOpChain.getOperations().get(0)).getView();
assertTrue(mergedView.isAllEntities());
assertEquals(0, mergedView.getEntities().size());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksOnExecuteFailureWhenRunningJob.
@Test
public void shouldCallAllGraphHooksOnExecuteFailureWhenRunningJob() throws OperationException {
// Given
final Operation operation = mock(Operation.class);
final OperationChain opChain = mock(OperationChain.class);
final OperationChain clonedOpChain = mock(OperationChain.class);
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final Schema schema = new Schema();
final RuntimeException e = new RuntimeException("Store failed to execute operation chain");
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
given(hook1.onFailure(null, clonedOpChain, clonedContext, e)).willThrow(new RuntimeException("Hook1 failed in onFailure"));
given(hook2.onFailure(null, clonedOpChain, clonedContext, e)).willReturn(null);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(hook1).addHook(hook2).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).build();
final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
given(store.executeJob(captor.capture(), eq(clonedContext))).willThrow(e);
// When / Then
try {
graph.executeJob(opChain, context);
fail("Exception expected");
} catch (final RuntimeException runtimeE) {
final InOrder inOrder = inOrder(context, hook1, hook2);
inOrder.verify(context).setOriginalOpChain(opChain);
inOrder.verify(hook1, never()).postExecute(any(), any(), any());
inOrder.verify(hook2, never()).postExecute(any(), any(), any());
inOrder.verify(hook1).onFailure(null, captor.getValue(), clonedContext, e);
inOrder.verify(hook2).onFailure(null, captor.getValue(), clonedContext, e);
final List<Operation> ops = captor.getValue().getOperations();
assertThat(ops).hasSize(1);
assertSame(operation, ops.get(0));
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldExposeGetTraitsMethod.
@Test
public void shouldExposeGetTraitsMethod() throws OperationException {
// Given
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
final View view = mock(View.class);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).store(store).build();
// When
final Set<StoreTrait> storeTraits = new HashSet<>(Arrays.asList(StoreTrait.INGEST_AGGREGATION, StoreTrait.TRANSFORMATION));
given(store.getTraits()).willReturn(storeTraits);
final Collection<StoreTrait> returnedTraits = graph.getStoreTraits();
// Then
assertEquals(returnedTraits, storeTraits);
}
Aggregations