Search in sources :

Example 81 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class FederatedAggregateHandlerTest method shouldAggregateDuplicatesFromDiffStores.

@Test
public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
    FederatedStoreProperties federatedStoreProperties = FederatedStoreProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "predefinedFederatedStore.properties"));
    final Graph fed = new Graph.Builder().config(new GraphConfig("fed")).addSchema(new Schema()).storeProperties(federatedStoreProperties).build();
    final String graphNameA = "a";
    final String graphNameB = "b";
    final Context context = new Context(new User());
    fed.execute(new OperationChain.Builder().first(new AddGraph.Builder().graphId(graphNameA).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).then(new AddGraph.Builder().graphId(graphNameB).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).build(), context);
    fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameA).build(), context);
    fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameB).build(), context);
    final CloseableIterable<? extends Element> getAll = fed.execute(new GetAllElements(), context);
    List<Element> list = new ArrayList<>();
    getAll.forEach(list::add);
    assertThat(list).hasSize(2);
    final Iterable<? extends Element> getAggregate = fed.execute(new OperationChain.Builder().first(new GetAllElements()).then(new Aggregate()).build(), context);
    list.clear();
    getAggregate.forEach(list::add);
    assertThat(list).hasSize(1);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) FederatedStoreProperties(uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) Test(org.junit.jupiter.api.Test)

Example 82 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class HBaseStoreTest method shouldBuildGraphAndGetGraphIdFromTableName.

@Test
public void shouldBuildGraphAndGetGraphIdFromTableName() throws Exception {
    // Given
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(HBaseStoreTest.class));
    properties.setTable("tableName");
    // When
    final Graph graph = new Graph.Builder().addSchemas(StreamUtil.schemas(getClass())).storeProperties(properties).build();
    // Then
    assertEquals("tableName", graph.getGraphId());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Test(org.junit.jupiter.api.Test)

Example 83 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class FederatedOperationOutputHandlerTest method shouldThrowException.

@Test
public void shouldThrowException() throws Exception {
    // Given
    final String message = "Test Exception";
    final OP op = getExampleOperation();
    op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, TEST_GRAPH_ID);
    Schema unusedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new StoreProperties();
    Store mockStoreInner = Mockito.mock(Store.class);
    given(mockStoreInner.getSchema()).willReturn(unusedSchema);
    given(mockStoreInner.getProperties()).willReturn(storeProperties);
    given(mockStoreInner.execute(any(OperationChain.class), any(Context.class))).willThrow(new RuntimeException(message));
    FederatedStore mockStore = Mockito.mock(FederatedStore.class);
    HashSet<Graph> filteredGraphs = Sets.newHashSet(getGraphWithMockStore(mockStoreInner));
    Mockito.when(mockStore.getGraphs(user, TEST_GRAPH_ID, op)).thenReturn(filteredGraphs);
    // When
    try {
        getFederatedHandler().doOperation(op, context, mockStore);
        fail("Exception not thrown");
    } catch (OperationException e) {
        assertEquals(message, e.getCause().getMessage());
    }
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Store(uk.gov.gchq.gaffer.store.Store) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 84 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class FederatedOperationOutputHandlerTest method shouldReturnEmptyIterableWhenNoResults.

@Test
public void shouldReturnEmptyIterableWhenNoResults() throws Exception {
    // Given
    final OP op = getExampleOperation();
    op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, TEST_GRAPH_ID);
    Schema unusedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new StoreProperties();
    Store mockStoreInner = Mockito.mock(Store.class);
    given(mockStoreInner.getSchema()).willReturn(unusedSchema);
    given(mockStoreInner.getProperties()).willReturn(storeProperties);
    given(mockStoreInner.execute(any(OperationChain.class), eq(context))).willReturn(null);
    FederatedStore mockStore = Mockito.mock(FederatedStore.class);
    HashSet<Graph> filteredGraphs = Sets.newHashSet(getGraphWithMockStore(mockStoreInner));
    Mockito.when(mockStore.getGraphs(user, TEST_GRAPH_ID, op)).thenReturn(filteredGraphs);
    // When
    final O results = getFederatedHandler().doOperation(op, context, mockStore);
    assertEquals(0, Iterables.size((Iterable) results));
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Store(uk.gov.gchq.gaffer.store.Store) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 85 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class FederatedOperationOutputHandlerTest method shouldNotThrowException.

@Test
public void shouldNotThrowException() throws Exception {
    // Given
    // Given
    final OP op = getExampleOperation();
    op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, "1,3");
    op.addOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE, String.valueOf(true));
    Schema unusedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new StoreProperties();
    Store mockStore1 = getMockStore(unusedSchema, storeProperties, o1);
    Store mockStore2 = getMockStore(unusedSchema, storeProperties, o2);
    Store mockStore3 = Mockito.mock(Store.class);
    given(mockStore3.getSchema()).willReturn(unusedSchema);
    given(mockStore3.getProperties()).willReturn(storeProperties);
    given(mockStore3.execute(any(OperationChain.class), eq(context))).willThrow(new RuntimeException("Test Exception"));
    Store mockStore4 = getMockStore(unusedSchema, storeProperties, o4);
    FederatedStore mockStore = Mockito.mock(FederatedStore.class);
    LinkedHashSet<Graph> filteredGraphs = Sets.newLinkedHashSet();
    filteredGraphs.add(getGraphWithMockStore(mockStore1));
    filteredGraphs.add(getGraphWithMockStore(mockStore3));
    Mockito.when(mockStore.getGraphs(user, "1,3", op)).thenReturn(filteredGraphs);
    // When
    O theMergedResultsOfOperation = null;
    try {
        theMergedResultsOfOperation = getFederatedHandler().doOperation(op, context, mockStore);
    } catch (Exception e) {
        fail("Exception should not have been thrown: " + e.getMessage());
    }
    // Then
    validateMergeResultsFromFieldObjects(theMergedResultsOfOperation, o1);
    ArgumentCaptor<Context> context1Captor = ArgumentCaptor.forClass(Context.class);
    verify(mockStore1).execute(any(OperationChain.class), context1Captor.capture());
    assertNotEquals(context.getJobId(), context1Captor.getValue().getJobId());
    assertEquals(context.getUser(), context1Captor.getValue().getUser());
    verify(mockStore2, never()).execute(any(OperationChain.class), any(Context.class));
    ArgumentCaptor<Context> context3Captor = ArgumentCaptor.forClass(Context.class);
    verify(mockStore3).execute(any(OperationChain.class), context3Captor.capture());
    assertNotEquals(context.getJobId(), context3Captor.getValue().getJobId());
    assertEquals(context.getUser(), context3Captor.getValue().getUser());
    verify(mockStore4, never()).execute(any(OperationChain.class), any(Context.class));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Store(uk.gov.gchq.gaffer.store.Store) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Aggregations

Graph (uk.gov.gchq.gaffer.graph.Graph)311 Test (org.junit.jupiter.api.Test)172 User (uk.gov.gchq.gaffer.user.User)155 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)146 Element (uk.gov.gchq.gaffer.data.element.Element)116 Schema (uk.gov.gchq.gaffer.store.schema.Schema)84 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)83 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)76 Edge (uk.gov.gchq.gaffer.data.element.Edge)75 HashSet (java.util.HashSet)71 Entity (uk.gov.gchq.gaffer.data.element.Entity)68 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)60 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)58 ArrayList (java.util.ArrayList)56 OperationException (uk.gov.gchq.gaffer.operation.OperationException)55 Test (org.junit.Test)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)44 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)44 Set (java.util.Set)38