use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptOutgoingEdges.
@Test
public void shouldOnlyAcceptOutgoingEdges() throws OperationException, AccumuloElementConversionException {
// Given
final ByteEntityRangeElementPropertyFilterIterator filter = new ByteEntityRangeElementPropertyFilterIterator();
final Map<String, String> options = new HashMap<String, String>() {
{
put(AccumuloStoreConstants.DIRECTED_EDGE_ONLY, "true");
put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "true");
}
};
filter.validateOptions(options);
// value should not be used
final Value value = null;
// When / Then
for (final Element element : ELEMENTS) {
final Pair<Key> keys = converter.getKeysFromElement(element);
final boolean expectedResult = element instanceof Edge && ((Edge) element).isDirected();
assertEquals("Failed for element: " + element.toString(), expectedResult, filter.accept(keys.getFirst(), value));
if (null != keys.getSecond()) {
// self elements are not added the other way round
assertEquals("Failed for element: " + element.toString(), false, filter.accept(keys.getSecond(), value));
}
}
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsBetweenSetsHandlerTest method shouldReturnSummarisedElements.
private void shouldReturnSummarisedElements(final AccumuloStore store) throws OperationException {
final View opView = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, opView);
final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
//With query compaction the result size should be 2
assertEquals(2, Iterables.size(elements));
assertThat(elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1));
elements.close();
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsBetweenSetsHandlerTest method setupGraph.
private static void setupGraph(final AccumuloStore store) {
List<Element> data = new ArrayList<>();
// Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
final Entity entity = new Entity(TestGroups.ENTITY, "A0");
entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
data.add(entity);
for (int i = 1; i < 100; i++) {
final Edge edge = new Edge(TestGroups.EDGE, "A0", "A" + i, true);
edge.putProperty(AccumuloPropertyNames.COUNT, 23);
edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
edge.putProperty(AccumuloPropertyNames.PROP_1, 0);
edge.putProperty(AccumuloPropertyNames.PROP_2, 0);
edge.putProperty(AccumuloPropertyNames.PROP_3, 0);
edge.putProperty(AccumuloPropertyNames.PROP_4, 0);
data.add(edge);
final Edge edge2 = new Edge(TestGroups.EDGE, "A0", "A" + i, true);
edge2.putProperty(AccumuloPropertyNames.COUNT, 23);
edge2.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 2);
data.add(edge2);
final Edge edge3 = new Edge(TestGroups.EDGE, "A0", "A" + i, true);
edge3.putProperty(AccumuloPropertyNames.COUNT, 23);
edge3.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 3);
data.add(edge3);
final Entity edgeEntity = new Entity(TestGroups.ENTITY, "A" + i);
edgeEntity.putProperty(AccumuloPropertyNames.COUNT, i);
data.add(edgeEntity);
}
addElements(data, store, new User());
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementPostAggregationFilterTest method shouldAcceptElementWhenViewValidatorAcceptsElement.
@Test
public void shouldAcceptElementWhenViewValidatorAcceptsElement() throws Exception {
// Given
final AbstractElementFilter filter = new ElementPostAggregationFilter();
final Map<String, String> options = new HashMap<>();
options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
options.put(AccumuloStoreConstants.VIEW, getViewJson());
options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
filter.validateOptions(options);
final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
final Pair<Key> key = converter.getKeysFromElement(element);
final Value value = converter.getValueFromElement(element);
// When
final boolean accept = filter.accept(key.getFirst(), value);
// Then
assertTrue(accept);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementPostAggregationFilterTest method shouldNotAcceptElementWhenViewValidatorDoesNotAcceptElement.
@Test
public void shouldNotAcceptElementWhenViewValidatorDoesNotAcceptElement() throws Exception {
// Given
final AbstractElementFilter filter = new ElementPostAggregationFilter();
final Map<String, String> options = new HashMap<>();
options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
options.put(AccumuloStoreConstants.VIEW, getEmptyViewJson());
options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
filter.validateOptions(options);
final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
final Pair<Key> key = converter.getKeysFromElement(element);
final Value value = converter.getValueFromElement(element);
// When
final boolean accept = filter.accept(key.getFirst(), value);
// Then
assertFalse(accept);
}
Aggregations