use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldSetGraphViewOnOperationAndDelegateDoOperationToStore.
@Test
public void shouldSetGraphViewOnOperationAndDelegateDoOperationToStore() throws OperationException {
// Given
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
final View view = new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build();
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).store(store).build();
final Integer expectedResult = 5;
final GetElements operation = new GetElements();
final OperationChain<Integer> opChain = mock(OperationChain.class);
final OperationChain clonedOpChain = mock(OperationChain.class);
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(clonedOpChain.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);
JsonAssert.assertEquals(view.toJson(false), operation.getView().toJson(false));
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksOnGraphHookPostExecuteFailureWhenRunningJob.
@Test
public void shouldCallAllGraphHooksOnGraphHookPostExecuteFailureWhenRunningJob() throws OperationException {
// Given
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final JobDetail result1 = mock(JobDetail.class);
final JobDetail result2 = mock(JobDetail.class);
final JobDetail result3 = mock(JobDetail.class);
final Schema schema = new Schema();
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
given(hook1.postExecute(result1, clonedOpChain, clonedContext)).willReturn(result2);
final RuntimeException e = new RuntimeException("Hook2 failed in postExecute");
given(hook2.postExecute(result2, clonedOpChain, clonedContext)).willThrow(e);
given(hook1.onFailure(result2, clonedOpChain, clonedContext, e)).willThrow(new RuntimeException("Hook1 failed in onFailure"));
given(hook2.onFailure(result2, clonedOpChain, clonedContext, e)).willReturn(result3);
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))).willReturn(result1);
// 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).postExecute(result1, captor.getValue(), clonedContext);
inOrder.verify(hook2).postExecute(result2, captor.getValue(), clonedContext);
inOrder.verify(hook1).onFailure(result2, captor.getValue(), clonedContext, e);
inOrder.verify(hook2).onFailure(result2, 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 shouldThrowExceptionIfGraphIdIsInvalid.
@Test
public void shouldThrowExceptionIfGraphIdIsInvalid() throws Exception {
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
try {
new Graph.Builder().config(new GraphConfig.Builder().graphId("invalid-id").build()).build();
fail("Exception expected");
} catch (final IllegalArgumentException e) {
assertNotNull(e.getMessage());
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.
@Test
public void shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
// Given
operation = new GetElements.Builder().build();
final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE)).build();
given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(clonedOpChain.flatten()).willReturn(Arrays.asList(operation));
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_5, new SchemaEdgeDefinition()).build());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(updateViewHook).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
given(store.execute(captor.capture(), contextCaptor1.capture())).willReturn(new ArrayList<>());
// When / Then
graph.execute(opChain, user);
final List<Operation> ops = captor.getValue().getOperations();
JsonAssert.assertEquals(new View.Builder().edge(TestGroups.EDGE_5).build().toCompactJson(), ((GetElements) ops.get(0)).getView().toCompactJson());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GafferResultCacheExporterTest method before.
@BeforeEach
public void before() {
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
resultCache = new Graph.Builder().config(new GraphConfig.Builder().graphId("resultCacheGraph").build()).store(store).build();
}
Aggregations