Search in sources :

Example 61 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class GraphTest method shouldConstructGraphFromSchemaModules.

@Test
public void shouldConstructGraphFromSchemaModules() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(StoreImpl.class.getName());
    final Schema schemaModule1 = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).build()).build();
    final Schema schemaModule2 = new Schema.Builder().type(TestTypes.PROP_INTEGER, new TypeDefinition.Builder().clazz(Integer.class).build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_2, TestTypes.PROP_INTEGER).build()).build();
    final Schema schemaModule3 = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).build()).build();
    final Schema schemaModule4 = new Schema.Builder().entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_2, TestTypes.PROP_INTEGER).build()).build();
    // When
    final Graph graph = new Graph.Builder().storeProperties(storeProperties).addSchema(schemaModule1).addSchema(schemaModule2).addSchema(schemaModule3).addSchema(schemaModule4).build();
    // Then
    final Schema schema = graph.getSchema();
    schema.getEntity(TestGroups.ENTITY);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.Test)

Example 62 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksAfterOperationExecuted.

@Test
public void shouldCallAllGraphHooksAfterOperationExecuted() throws OperationException {
    // Given
    final Operation operation = mock(Operation.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.singletonList(operation));
    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 Object result1 = mock(Object.class);
    final Object result2 = mock(Object.class);
    final Object result3 = mock(Object.class);
    final Schema schema = new Schema();
    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();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    given(store.execute(captor.capture(), Mockito.eq(user))).willReturn(result1);
    // When
    final Object actualResult = graph.execute(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).postExecute(result1, captor.getValue(), user);
    inOrder.verify(hook2).postExecute(result2, captor.getValue(), user);
    final List<Operation> ops = captor.getValue().getOperations();
    assertEquals(1, ops.size());
    assertSame(operation, ops.get(0));
    assertSame(actualResult, result3);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) Test(org.junit.Test)

Example 63 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class GafferResultCacheUtilTest method shouldCreateGraphWithValidSchemaWithoutAgeOff.

@Test
public void shouldCreateGraphWithValidSchemaWithoutAgeOff() {
    // Given
    final Graph graph = GafferResultCacheUtil.createGraph(StreamUtil.STORE_PROPERTIES, null);
    final Schema schema = graph.getSchema();
    // When
    final boolean isValid = schema.validate();
    // Then
    assertTrue(isValid);
    assertNull(schema.getType("timestamp").getValidator());
    assertTrue(new ElementValidator(schema).validate(validEdge));
    assertTrue(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 64 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class JcsJobTrackerIT method setup.

@Before
public void setup() throws Exception {
    final StoreProperties storeProps = StoreProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    store = Class.forName(storeProps.getStoreClass()).asSubclass(Store.class).newInstance();
    store.initialise(new Schema(), storeProps);
    graph = new Graph.Builder().store(store).build();
    clearJobTracker();
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Before(org.junit.Before)

Example 65 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class SingleUseMockAccumuloProxyStore method initialise.

@Override
public void initialise(final Schema accumuloSchema, final StoreProperties proxyProps) throws StoreException {
    startMockAccumuloRestApi(accumuloSchema);
    super.initialise(new Schema(), proxyProps);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema)

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