Search in sources :

Example 16 with StoreTrait

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

the class GetTraitsHandlerTest method getStoreTraits.

private Set<StoreTrait> getStoreTraits(final Schema schema) throws StoreException, uk.gov.gchq.gaffer.operation.OperationException {
    store.initialise(STORE_ID, schema, new StoreProperties());
    Set<StoreTrait> execute = store.execute(new GetTraits.Builder().currentTraits(true).build(), new Context(testUser()));
    final Set<StoreTrait> actual = Sets.newHashSet(execute);
    assertFalse(actual.isEmpty());
    return actual;
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) GetTraits(uk.gov.gchq.gaffer.store.operation.GetTraits) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 17 with StoreTrait

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

the class GraphTest method shouldExposeGetTraitsMethod.

@Test
public void shouldExposeGetTraitsMethod() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(new Schema());
    given(store.getProperties()).willReturn(new StoreProperties());
    final View view = mock(View.class);
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).store(store).build();
    // When
    final Set<StoreTrait> storeTraits = new HashSet<>(Arrays.asList(StoreTrait.INGEST_AGGREGATION, StoreTrait.TRANSFORMATION));
    given(store.getTraits()).willReturn(storeTraits);
    final Collection<StoreTrait> returnedTraits = graph.getStoreTraits();
    // Then
    assertEquals(returnedTraits, storeTraits);
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with StoreTrait

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

the class AbstractStoreIT method validateTraits.

protected void validateTraits() {
    final Collection<StoreTrait> requiredTraits = new ArrayList<>();
    for (final Annotation annotation : method.getDeclaredAnnotations()) {
        if (annotation.annotationType().equals(TraitRequirement.class)) {
            final TraitRequirement traitRequirement = (TraitRequirement) annotation;
            requiredTraits.addAll(Arrays.asList(traitRequirement.value()));
        }
    }
    for (final StoreTrait requiredTrait : requiredTraits) {
        assumeThat(graph.hasTrait(requiredTrait)).as("Skipping test as the store does not implement all required traits.").isTrue();
    }
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation)

Example 19 with StoreTrait

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

the class GraphConfigurationServiceV2Test method setup.

@BeforeEach
public void setup() {
    final Set<StoreTrait> traits = new HashSet<>(Arrays.asList(INGEST_AGGREGATION, PRE_AGGREGATION_FILTERING, POST_TRANSFORMATION_FILTERING, POST_AGGREGATION_FILTERING, TRANSFORMATION, STORE_VALIDATION));
    lenient().when(store.getSchema()).thenReturn(new Schema());
    lenient().when(store.getProperties()).thenReturn(new StoreProperties());
    lenient().when(store.getGraphId()).thenReturn(GRAPH_ID);
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(// This graphId is not used as store is mocked
    GRAPH_ID).build()).description("test graph").store(store).build();
    final StoreProperties props = new StoreProperties();
    lenient().when(store.getProperties()).thenReturn(props);
    final Set<Class<? extends Operation>> operations = new HashSet<>();
    operations.add(AddElements.class);
    lenient().when(graphFactory.getGraph()).thenReturn(graph);
    lenient().when(graph.getSupportedOperations()).thenReturn(operations);
    lenient().when(graph.isSupported(AddElements.class)).thenReturn(true);
    lenient().when(userFactory.createContext()).thenReturn(new Context());
    lenient().when(graph.getStoreTraits()).thenReturn(traits);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Graph(uk.gov.gchq.gaffer.graph.Graph) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Operation(uk.gov.gchq.gaffer.operation.Operation) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with StoreTrait

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

the class FederatedGetTraitsHandler method doOperation.

@Override
public Set<StoreTrait> doOperation(final GetTraits operation, final Context context, final Store store) throws OperationException {
    try {
        FederatedOperationChain<Void, StoreTrait> wrappedFedChain = new FederatedOperationChain.Builder<Void, StoreTrait>().operationChain(OperationChain.wrap(operation)).options(isNull(operation.getOptions()) ? new HashMap<>() : new HashMap<>(operation.getOptions())).build();
        final CloseableIterable<StoreTrait> concatResults = store.execute(wrappedFedChain, context);
        Map<StoreTrait, Integer> rtn;
        if (nonNull(concatResults) && nonNull(concatResults.iterator()) && concatResults.iterator().hasNext()) {
            rtn = Streams.toStream(concatResults).collect(Collectors.toMap(t -> t, ignore -> 1, (existing, replacement) -> existing + replacement));
            long graphIdsSize = ((FederatedStore) store).getGraphs(context.getUser(), operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS), operation).stream().count();
            rtn.values().removeIf(v -> v < graphIdsSize);
        } else {
            rtn = Collections.EMPTY_MAP;
        }
        return rtn.keySet();
    } catch (final Exception e) {
        throw new OperationException("Error getting federated traits.", e);
    }
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Aggregations

StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)29 Schema (uk.gov.gchq.gaffer.store.schema.Schema)16 Test (org.junit.jupiter.api.Test)15 Context (uk.gov.gchq.gaffer.store.Context)11 HashSet (java.util.HashSet)9 Graph (uk.gov.gchq.gaffer.graph.Graph)8 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)8 GetTraits (uk.gov.gchq.gaffer.store.operation.GetTraits)8 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)7 GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)4 Test (org.junit.Test)3 MapStoreProperties (uk.gov.gchq.gaffer.mapstore.MapStoreProperties)3 Operation (uk.gov.gchq.gaffer.operation.Operation)3 Store (uk.gov.gchq.gaffer.store.Store)3 Annotation (java.lang.annotation.Annotation)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 Before (org.junit.Before)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2