Search in sources :

Example 11 with Schema

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());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Example 12 with Schema

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);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 13 with Schema

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());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.Test)

Example 14 with Schema

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());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with Schema

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);
}
Also used : Path(org.apache.hadoop.fs.Path) AddElementsFromHdfs(uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs) User(uk.gov.gchq.gaffer.user.User) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter) FileSystem(org.apache.hadoop.fs.FileSystem) SplitTable(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.operation.SplitTable) Job(org.apache.hadoop.mapreduce.Job) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Aggregations

Schema (uk.gov.gchq.gaffer.store.schema.Schema)86 Test (org.junit.Test)63 SQLContext (org.apache.spark.sql.SQLContext)14 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)13 User (uk.gov.gchq.gaffer.user.User)13 HashSet (java.util.HashSet)12 Filter (org.apache.spark.sql.sources.Filter)12 EqualTo (org.apache.spark.sql.sources.EqualTo)9 MockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore)9 SingleUseMockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore)9 Element (uk.gov.gchq.gaffer.data.element.Element)9 Store (uk.gov.gchq.gaffer.store.Store)9 Before (org.junit.Before)8 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)8 Graph (uk.gov.gchq.gaffer.graph.Graph)8 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5