use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldCloseAllOperationInputsWhenExceptionIsThrownWhenExecuted.
@Test
public void shouldCloseAllOperationInputsWhenExceptionIsThrownWhenExecuted() throws OperationException, IOException {
// Given
final Exception exception = mock(RuntimeException.class);
final Store store = mock(Store.class);
given(store.execute(clonedOpChain, clonedContext)).willThrow(exception);
final Schema schema = new Schema();
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(// skips json serialisation in default hook
new FunctionAuthoriser()).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(new Schema.Builder().build()).build();
// When / Then
try {
graph.execute(opChain, context);
fail("Exception expected");
} catch (final Exception e) {
assertSame(exception, e);
verify(clonedOpChain).close();
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldCloseAllOperationInputsWhenExceptionIsThrownWhenJobExecuted.
@Test
public void shouldCloseAllOperationInputsWhenExceptionIsThrownWhenJobExecuted() throws OperationException, IOException {
// Given
final Exception exception = mock(RuntimeException.class);
final Store store = mock(Store.class);
given(store.executeJob(clonedOpChain, clonedContext)).willThrow(exception);
final Schema schema = new Schema();
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(// skips json serialisation in default hook
new FunctionAuthoriser()).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(new Schema.Builder().build()).build();
// When / Then
try {
graph.executeJob(opChain, context);
fail("Exception expected");
} catch (final Exception e) {
assertSame(exception, e);
verify(clonedOpChain).close();
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksBeforeOperationChainExecuted.
@Test
public void shouldCallAllGraphHooksBeforeOperationChainExecuted() throws OperationException {
// Given
final Store store = mock(Store.class);
final Schema schema = new Schema();
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
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(new Schema.Builder().build()).build();
// When
graph.execute(opChain, context);
// Then
final InOrder inOrder = inOrder(hook1, hook2, operation);
inOrder.verify(hook1).preExecute(clonedOpChain, clonedContext);
inOrder.verify(hook2).preExecute(clonedOpChain, clonedContext);
inOrder.verify(operation).setView(Mockito.any(View.class));
verify(context).setOriginalOpChain(opChain);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldGetSchemaFromStoreIfSchemaIsEmpty.
@Test
public void shouldGetSchemaFromStoreIfSchemaIsEmpty() throws OperationException {
// Given
final Store store = mock(Store.class);
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").build()).type("string", String.class).build();
given(store.getSchema()).willReturn(schema);
given(store.getOriginalSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
final View view = mock(View.class);
new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).addSchema(new Schema()).store(store).build();
// When
verify(store).setOriginalSchema(schema);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksAfterJobExecuted.
@Test
public void shouldCallAllGraphHooksAfterJobExecuted() throws OperationException {
// Given
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final Schema schema = new Schema();
final JobDetail result1 = mock(JobDetail.class);
final JobDetail result2 = mock(JobDetail.class);
final JobDetail result3 = mock(JobDetail.class);
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
given(hook1.postExecute(result1, clonedOpChain, clonedContext)).willReturn(result2);
given(hook2.postExecute(result2, clonedOpChain, clonedContext)).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();
given(store.executeJob(clonedOpChain, clonedContext)).willReturn(result1);
// When
final JobDetail actualResult = graph.executeJob(opChain, context);
// Then
final InOrder inOrder = inOrder(hook1, hook2);
inOrder.verify(hook1).postExecute(result1, clonedOpChain, clonedContext);
inOrder.verify(hook2).postExecute(result2, clonedOpChain, clonedContext);
assertSame(actualResult, result3);
verify(context).setOriginalOpChain(opChain);
}
Aggregations