Search in sources :

Example 41 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationExample method createExampleGraph.

protected Graph createExampleGraph() {
    final Graph graph = new Graph.Builder().addSchemas(StreamUtil.openStreams(getClass(), "/example/operation/schema")).storeProperties(StreamUtil.openStream(getClass(), "/example/operation/mockaccumulostore.properties")).build();
    // Create data generator
    final DataGenerator dataGenerator = new DataGenerator();
    // Load data into memory
    final List<String> data = DataUtils.loadData(StreamUtil.openStream(getClass(), "/example/operation/data.txt", true));
    //add the edges to the graph using an operation chain consisting of:
    //generateElements - generating edges from the data (note these are directed edges)
    //addElements - add the edges to the graph
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(dataGenerator).objects(data).build()).then(new AddElements()).build();
    try {
        graph.execute(addOpChain, new User());
    } catch (OperationException e) {
        throw new RuntimeException(e);
    }
    return graph;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) DataGenerator(uk.gov.gchq.gaffer.example.operation.generator.DataGenerator) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 42 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class ExamplesServiceTest method shouldSerialiseAndDeserialiseOperationChain.

@Test
public void shouldSerialiseAndDeserialiseOperationChain() throws IOException {
    //Given
    final OperationChain opChain = service.execute();
    // When
    byte[] bytes = serialiser.serialise(opChain);
    final OperationChain deserialisedOp = serialiser.deserialise(bytes, opChain.getClass());
    // Then
    assertNotNull(deserialisedOp);
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 43 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksBeforeOperationExecuted.

@Test
public void shouldCallAllGraphHooksBeforeOperationExecuted() throws OperationException {
    // Given
    final Operation operation = mock(Operation.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.singletonList(operation));
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).addSchema(new Schema.Builder().build()).addHook(hook1).addHook(hook2).build();
    // When
    graph.execute(opChain, user);
    // Then
    final ArgumentCaptor<OperationChain> captor1 = ArgumentCaptor.forClass(OperationChain.class);
    final ArgumentCaptor<OperationChain> captor2 = ArgumentCaptor.forClass(OperationChain.class);
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).preExecute(captor1.capture(), Mockito.eq(user));
    inOrder.verify(hook2).preExecute(captor2.capture(), Mockito.eq(user));
    assertSame(captor1.getValue(), captor2.getValue());
    final List<Operation> ops = captor1.getValue().getOperations();
    assertEquals(1, ops.size());
    assertSame(operation, ops.get(0));
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Operation(uk.gov.gchq.gaffer.operation.Operation) Test(org.junit.Test)

Example 44 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksAfterOperationChainExecuted.

@Test
public void shouldCallAllGraphHooksAfterOperationChainExecuted() throws OperationException {
    // Given
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Store store = mock(Store.class);
    final Schema schema = new Schema();
    final Object result1 = mock(Object.class);
    final Object result2 = mock(Object.class);
    final Object result3 = mock(Object.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(store.getSchema()).willReturn(schema);
    given(hook1.postExecute(result1, opChain, user)).willReturn(result2);
    given(hook2.postExecute(result2, opChain, user)).willReturn(result3);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).addHook(hook1).addHook(hook2).build();
    given(opChain.getOperations()).willReturn(Collections.singletonList(mock(Operation.class)));
    given(store.execute(opChain, user)).willReturn(result1);
    // When
    final Object actualResult = graph.execute(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).postExecute(result1, opChain, user);
    inOrder.verify(hook2).postExecute(result2, opChain, user);
    assertSame(actualResult, result3);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 45 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksAfterOperationExecuted.

@Test
public void shouldCallAllGraphHooksAfterOperationExecuted() throws OperationException {
    // Given
    final Operation operation = mock(Operation.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.singletonList(operation));
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Store store = mock(Store.class);
    final Object result1 = mock(Object.class);
    final Object result2 = mock(Object.class);
    final Object result3 = mock(Object.class);
    final Schema schema = new Schema();
    given(store.getSchema()).willReturn(schema);
    given(hook1.postExecute(result1, opChain, user)).willReturn(result2);
    given(hook2.postExecute(result2, opChain, user)).willReturn(result3);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).addHook(hook1).addHook(hook2).build();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    given(store.execute(captor.capture(), Mockito.eq(user))).willReturn(result1);
    // When
    final Object actualResult = graph.execute(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).postExecute(result1, captor.getValue(), user);
    inOrder.verify(hook2).postExecute(result2, captor.getValue(), user);
    final List<Operation> ops = captor.getValue().getOperations();
    assertEquals(1, ops.size());
    assertSame(operation, ops.get(0));
    assertSame(actualResult, result3);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) Test(org.junit.Test)

Aggregations

OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)65 Test (org.junit.Test)52 User (uk.gov.gchq.gaffer.user.User)38 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 Store (uk.gov.gchq.gaffer.store.Store)13 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)9 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 InOrder (org.mockito.InOrder)6 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6