Search in sources :

Example 1 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedAggregateHandlerTest method shouldDelegateToHandler.

@Test
public void shouldDelegateToHandler() throws OperationException {
    // Given
    final FederatedStore store = mock(FederatedStore.class);
    final AggregateHandler handler = mock(AggregateHandler.class);
    final Aggregate op = mock(Aggregate.class);
    final Context context = mock(Context.class);
    final Iterable expectedResult = mock(Iterable.class);
    final Schema schema = mock(Schema.class);
    given(store.getSchema(op, context)).willReturn(schema);
    given(handler.doOperation(op, schema)).willReturn(expectedResult);
    final FederatedAggregateHandler federatedHandler = new FederatedAggregateHandler(handler);
    // When
    final Object result = federatedHandler.doOperation(op, context, store);
    // Then
    assertSame(expectedResult, result);
    verify(handler).doOperation(op, schema);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AggregateHandler(uk.gov.gchq.gaffer.store.operation.handler.function.AggregateHandler) FederatedAggregateHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedAggregateHandler) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) FederatedAggregateHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedAggregateHandler) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 2 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedGetAllGraphsIDHandlerTest method shouldGetGraphIds.

@Test
public void shouldGetGraphIds() throws Exception {
    FederatedGetAllGraphIDHandler federatedGetAllGraphIDHandler = new FederatedGetAllGraphIDHandler();
    GetAllGraphIds op = Mockito.mock(GetAllGraphIds.class);
    Context context = Mockito.mock(Context.class);
    BDDMockito.given(context.getUser()).willReturn(testUser);
    FederatedStore store = Mockito.mock(FederatedStore.class);
    Set<String> expected = Sets.newHashSet();
    expected.add("value1");
    BDDMockito.given(store.getAllGraphIds(testUser, false)).willReturn(expected);
    Iterable<? extends String> actual = federatedGetAllGraphIDHandler.doOperation(op, context, store);
    assertEquals(expected, actual);
    Mockito.verify(store).getAllGraphIds(testUser, false);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 3 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore 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 4 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore 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 5 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore 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

FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)38 Test (org.junit.jupiter.api.Test)25 Context (uk.gov.gchq.gaffer.store.Context)25 Schema (uk.gov.gchq.gaffer.store.schema.Schema)19 Graph (uk.gov.gchq.gaffer.graph.Graph)16 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)12 OperationException (uk.gov.gchq.gaffer.operation.OperationException)12 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)11 Store (uk.gov.gchq.gaffer.store.Store)10 FederatedOperationChain (uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain)8 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)7 FederatedStoreProperties (uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties)7 PredefinedFederatedStore (uk.gov.gchq.gaffer.federatedstore.PredefinedFederatedStore)7 Operation (uk.gov.gchq.gaffer.operation.Operation)7 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)6 User (uk.gov.gchq.gaffer.user.User)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Element (uk.gov.gchq.gaffer.data.element.Element)4 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)4 GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)4