Search in sources :

Example 76 with Schema

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

the class StoreTest method shouldHandleMultiStepOperations.

@Test
public void shouldHandleMultiStepOperations() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    final CloseableIterable<Element> getElementsResult = mock(CloseableIterable.class);
    final AddElements addElements1 = new AddElements();
    final GetElements<ElementSeed, Element> getElements = new GetElements<>();
    final OperationChain<CloseableIterable<Element>> opChain = new OperationChain.Builder().first(addElements1).then(getElements).build();
    given(addElementsHandler.doOperation(addElements1, context, store)).willReturn(null);
    given(getElementsHandler.doOperation(getElements, context, store)).willReturn(getElementsResult);
    store.initialise(schema, properties);
    // When
    final CloseableIterable<Element> result = store.execute(opChain, user);
    // Then
    assertSame(getElementsResult, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test)

Example 77 with Schema

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

the class StoreTest method shouldThrowExceptionWhenPropertyIsNotSerialisable.

@Test
public void shouldThrowExceptionWhenPropertyIsNotSerialisable() throws StoreException {
    // Given
    final Schema mySchema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "invalidType").build()).type("invalidType", new TypeDefinition.Builder().clazz(Object.class).serialiser(new StringSerialiser()).build()).build();
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    // When
    try {
        store.initialise(mySchema, properties);
        fail();
    } catch (final SchemaException exception) {
        assertNotNull(exception.getMessage());
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.Test)

Example 78 with Schema

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

the class StoreTest method createSchemaMock.

private Schema createSchemaMock() {
    final Schema schema = mock(Schema.class);
    given(schema.validate()).willReturn(true);
    given(schema.getVertexSerialiser()).willReturn(mock(Serialisation.class));
    return schema;
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation)

Example 79 with Schema

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

the class StoreIT method shouldCreateStoreAndValidateSchemas.

@Test
public void shouldCreateStoreAndValidateSchemas() throws IOException, SchemaException, StoreException {
    // Given
    final TestStore testStore = new TestStore();
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    // When
    testStore.initialise(schema, new StoreProperties());
    // Then
    assertTrue(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE));
    assertTrue(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE));
    assertTrue(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY));
    assertTrue(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY));
    assertFalse(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE_2));
    assertFalse(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY_2));
    assertFalse(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE_2));
    assertFalse(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY_2));
    assertTrue(testStore.getSchema().validate());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.Test)

Example 80 with Schema

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

the class CoreOperationChainOptimiserTest method shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation.

@Test
public void shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final Schema schema = mock(Schema.class);
    final Validatable<Integer> validatable1 = mock(Validatable.class);
    final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
    given(schema.validate()).willReturn(true);
    given(store.isValidationRequired()).willReturn(true);
    given(validatable1.isValidate()).willReturn(false);
    // When / then
    try {
        optimiser.optimise(opChain);
    } catch (UnsupportedOperationException e) {
        assertNotNull(e);
    }
}
Also used : 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)

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