Search in sources :

Example 36 with StoreProperties

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();
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) IOException(java.io.IOException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) URISyntaxException(java.net.URISyntaxException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 37 with StoreProperties

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();
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) IOException(java.io.IOException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) URISyntaxException(java.net.URISyntaxException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 38 with StoreProperties

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);
}
Also used : InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 39 with StoreProperties

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);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 40 with StoreProperties

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);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)170 Test (org.junit.jupiter.api.Test)136 Schema (uk.gov.gchq.gaffer.store.schema.Schema)102 Store (uk.gov.gchq.gaffer.store.Store)74 Context (uk.gov.gchq.gaffer.store.Context)47 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)42 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)39 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)26 Graph (uk.gov.gchq.gaffer.graph.Graph)26 Operation (uk.gov.gchq.gaffer.operation.Operation)24 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)20 User (uk.gov.gchq.gaffer.user.User)18 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)17 BeforeEach (org.junit.jupiter.api.BeforeEach)16 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)16 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)16 ExportToOtherGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph)14 HashSet (java.util.HashSet)13 FunctionAuthoriser (uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser)13