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);
}
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());
}
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());
}
}
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));
}
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));
}
Aggregations