use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class GafferResultCacheUtilTest method shouldCreateGraphWithValidSchema.
@Test
public void shouldCreateGraphWithValidSchema() {
// Given
final Graph graph = GafferResultCacheUtil.createGraph(StreamUtil.STORE_PROPERTIES, GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE);
final Schema schema = graph.getSchema();
// When
final boolean isValid = schema.validate();
// Then
assertTrue(isValid);
assertEquals(GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE, ((AgeOff) (schema.getType("timestamp").getValidator().getFunctions().get(0).getFunction())).getAgeOffTime());
assertTrue(new ElementValidator(schema).validate(validEdge));
assertFalse(new ElementValidator(schema).validate(oldEdge));
assertTrue(schema.validate());
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksAfterJobExecuted.
@Test
public void shouldCallAllGraphHooksAfterJobExecuted() 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 JobDetail result1 = mock(JobDetail.class);
final JobDetail result2 = mock(JobDetail.class);
final JobDetail result3 = mock(JobDetail.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.executeJob(opChain, user)).willReturn(result1);
// When
final JobDetail actualResult = graph.executeJob(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 shouldThrowExceptionIfStoreClassPropertyIsNotSet.
@Test
public void shouldThrowExceptionIfStoreClassPropertyIsNotSet() throws OperationException {
try {
new Graph.Builder().addSchema(new Schema()).storeProperties(new StoreProperties()).build();
fail("exception expected");
} catch (final IllegalArgumentException e) {
assertEquals("The Store class name was not found in the store properties for key: " + StoreProperties.STORE_CLASS, e.getMessage());
}
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class GraphTest method shouldConstructGraphAndCreateViewWithGroups.
@Test
public void shouldConstructGraphAndCreateViewWithGroups() {
// Given
final Store store = mock(Store.class);
final Schema schema = mock(Schema.class);
given(store.getSchema()).willReturn(schema);
final Set<String> edgeGroups = new HashSet<>();
edgeGroups.add("edge1");
edgeGroups.add("edge2");
edgeGroups.add("edge3");
edgeGroups.add("edge4");
given(schema.getEdgeGroups()).willReturn(edgeGroups);
final Set<String> entityGroups = new HashSet<>();
entityGroups.add("entity1");
entityGroups.add("entity2");
entityGroups.add("entity3");
entityGroups.add("entity4");
given(schema.getEntityGroups()).willReturn(entityGroups);
// When
final View resultView = new Graph.Builder().store(store).build().getView();
// Then
assertNotSame(schema, resultView);
assertArrayEquals(entityGroups.toArray(), resultView.getEntityGroups().toArray());
assertArrayEquals(edgeGroups.toArray(), resultView.getEdgeGroups().toArray());
for (final ViewElementDefinition resultElementDef : resultView.getEntities().values()) {
assertNotNull(resultElementDef);
assertEquals(0, resultElementDef.getTransientProperties().size());
assertNull(resultElementDef.getTransformer());
}
for (final ViewElementDefinition resultElementDef : resultView.getEdges().values()) {
assertNotNull(resultElementDef);
assertEquals(0, resultElementDef.getTransientProperties().size());
assertNull(resultElementDef.getTransformer());
}
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class AccumuloAddElementsFromHdfsJobFactoryTest method shouldSetNoLessThanMinNumberOfReducersSpecified.
@Test
public void shouldSetNoLessThanMinNumberOfReducersSpecified() throws IOException, StoreException, OperationException {
// Given
final MockAccumuloStore store = new MockAccumuloStore();
final Schema schema = Schema.fromJson(StreamUtil.schemas(AccumuloAddElementsFromHdfsJobFactoryTest.class));
final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(AccumuloAddElementsFromHdfsJobFactoryTest.class));
store.initialise(schema, properties);
final JobConf localConf = createLocalConf();
final FileSystem fs = FileSystem.getLocal(localConf);
fs.mkdirs(new Path(outputDir));
fs.mkdirs(new Path(splitsDir));
final BufferedWriter writer = new BufferedWriter(new FileWriter(splitsFile));
for (int i = 100; i < 200; i++) {
writer.write(i + "\n");
}
writer.close();
final SplitTable splitTable = new SplitTable.Builder().inputPath(splitsFile).build();
store.execute(splitTable, new User());
final AccumuloAddElementsFromHdfsJobFactory factory = new AccumuloAddElementsFromHdfsJobFactory();
final Job job = Job.getInstance(localConf);
// When
AddElementsFromHdfs operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).mapperGenerator(TextMapperGeneratorImpl.class).option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MIN_REDUCERS, "10").option(AccumuloStoreConstants.OPERATION_HDFS_SPLITS_FILE_PATH, "target/data/splits.txt").build();
factory.setupJobConf(localConf, operation, store);
factory.setupJob(job, operation, store);
// Then
assertTrue(job.getNumReduceTasks() >= 10);
// When
operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).mapperGenerator(TextMapperGeneratorImpl.class).option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MIN_REDUCERS, "100").option(AccumuloStoreConstants.OPERATION_HDFS_SPLITS_FILE_PATH, "target/data/splits.txt").build();
factory.setupJobConf(localConf, operation, store);
factory.setupJob(job, operation, store);
// Then
assertTrue(job.getNumReduceTasks() >= 100);
// When
operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).mapperGenerator(TextMapperGeneratorImpl.class).option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MIN_REDUCERS, "1000").option(AccumuloStoreConstants.OPERATION_HDFS_SPLITS_FILE_PATH, "target/data/splits.txt").build();
factory.setupJobConf(localConf, operation, store);
factory.setupJob(job, operation, store);
// Then
assertTrue(job.getNumReduceTasks() >= 1000);
}
Aggregations