use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class FilterToOperationConverterTest method testIncompatibleGroups.
@Test
public void testIncompatibleGroups() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testIncompatibleGroups");
final Filter[] filters = new Filter[2];
filters[0] = new EqualTo(SchemaToStructTypeConverter.GROUP, "A");
filters[1] = new EqualTo(SchemaToStructTypeConverter.GROUP, "B");
final FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
final AbstractGetRDD<?> operation = converter.getOperation();
assertNull(operation);
sqlContext.sparkContext().stop();
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifyDestination.
@Test
public void testSpecifyDestination() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testSpecifyDestination");
final Filter[] filters = new Filter[1];
filters[0] = new EqualTo(SchemaToStructTypeConverter.DST_COL_NAME, "0");
final FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
final AbstractGetRDD<?> operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(0, operation.getView().getEntityGroups().size());
assertEquals(EDGE_GROUPS, operation.getView().getEdgeGroups());
final Set<EntitySeed> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getSeeds()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
sqlContext.sparkContext().stop();
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class FilterToOperationConverterTest method testTwoGroups.
@Test
public void testTwoGroups() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testTwoGroups");
final Filter[] filters = new Filter[1];
final Filter left = new EqualTo(SchemaToStructTypeConverter.GROUP, ENTITY_GROUP);
final Filter right = new EqualTo(SchemaToStructTypeConverter.GROUP, EDGE_GROUP2);
filters[0] = new Or(left, right);
final FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
final AbstractGetRDD<?> operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfAllElements);
assertEquals(Collections.singleton(ENTITY_GROUP), operation.getView().getEntityGroups());
assertEquals(Collections.singleton(EDGE_GROUP2), operation.getView().getEdgeGroups());
sqlContext.sparkContext().stop();
}
use of uk.gov.gchq.gaffer.store.schema.Schema 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);
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class GraphTest method shouldConstructGraphFromSchemaFolderPath.
@Test
public void shouldConstructGraphFromSchemaFolderPath() throws IOException {
// Given
final Schema expectedSchema = new Schema.Builder().json(StreamUtil.dataSchema(getClass()), StreamUtil.dataTypes(getClass())).build();
Graph graph = null;
File schemaDir = null;
try {
schemaDir = createSchemaDirectory();
// When
graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).addSchema(Paths.get(schemaDir.getPath())).build();
} finally {
if (null != schemaDir) {
FileUtils.deleteDirectory(schemaDir);
}
}
// Then
JsonUtil.assertEquals(expectedSchema.toJson(true), graph.getSchema().toJson(true));
}
Aggregations