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;
}
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);
}
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();
}
}
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);
}
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);
}
}
Aggregations