use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class BloomFilterIT method calculateRandomLookUpRate.
private double calculateRandomLookUpRate(final FileSKVIterator reader, final HashSet<Entity> dataSet, final Random random, final RangeFactory rangeFactory) throws IOException, AccumuloElementConversionException, RangeFactoryException {
final EntitySeed[] randomData = new EntitySeed[5000];
for (int i = 0; i < 5000; i++) {
randomData[i] = new EntitySeed("type" + random.nextInt(Integer.MAX_VALUE));
}
final long start = System.currentTimeMillis();
for (int i = 0; i < 5000; i++) {
seek(reader, randomData[i], rangeFactory);
if (dataSet.contains(randomData[i])) {
assertTrue(reader.hasTop());
}
}
final long end = System.currentTimeMillis();
final double randomRate = 5000 / ((end - start) / 1000.0);
LOGGER.info("Random look up rate = " + randomRate);
return randomRate;
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class EntitySeedExtractorTest method shouldGetDestinationFromEdge.
@Test
public void shouldGetDestinationFromEdge() {
// Given
final EntitySeedExtractor extractor = new EntitySeedExtractor(IdentifierType.DESTINATION);
final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", false);
// When
final EntitySeed seed = extractor.getObject(edge);
// Then
assertEquals("destination", seed.getVertex());
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method shouldStillApplyOtherFilter.
private void shouldStillApplyOtherFilter(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
// Query for all edges in set {A0, A23}
final Set<EntitySeed> seeds = new HashSet<>();
seeds.add(AccumuloTestData.SEED_A0);
seeds.add(AccumuloTestData.SEED_A23);
final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
// Set graph to give us edges only
op.setIncludeEntities(false);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A0_A23));
// Set graph to return entities only
final GetElements<EntitySeed, ?> entitiesOnlyOp = new GetElements<>(defaultView, seeds);
entitiesOnlyOp.setIncludeEntities(true);
entitiesOnlyOp.setIncludeEdges(IncludeEdgeType.NONE);
// Query for all edges in set {A0, A23}
final Set<Element> entitiesOnlyResults = returnElementsFromOperation(store, entitiesOnlyOp, new User(), loadIntoMemory);
assertThat(entitiesOnlyResults, IsCollectionContaining.hasItems(AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY));
// Set graph to return both entities and edges again, and to only return summary type "X" (which will result
// in no data)
final View view = new View.Builder().edge("X").build();
final GetElements<EntitySeed, ?> entitiesAndEdgesOp = new GetElements<>(view, seeds);
entitiesAndEdgesOp.setIncludeEdges(IncludeEdgeType.ALL);
entitiesAndEdgesOp.setIncludeEntities(true);
final Set<Element> entitiesAndEdgesResults = returnElementsFromOperation(store, entitiesAndEdgesOp, new User(), loadIntoMemory);
assertEquals(0, entitiesAndEdgesResults.size());
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.
private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
final Set<EntitySeed> seeds = new HashSet<>();
seeds.add(new EntitySeed("C"));
seeds.add(new EntitySeed("D"));
final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
// Set undirected edges only option, and query for edges in set {C, D} - should get the undirected edge
op.setIncludeEdges(GetOperation.IncludeEdgeType.UNDIRECTED);
op.setIncludeEntities(false);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_C_D_UNDIRECTED));
// Set directed edges only option, and query for edges in set {C, D} - should get the directed edge
final GetElements<EntitySeed, ?> directedCOop = new GetElements<>(defaultView, seeds);
directedCOop.setIncludeEdges(IncludeEdgeType.DIRECTED);
final Set<Element> directedCDResults = returnElementsFromOperation(store, directedCOop, new User(), loadIntoMemory);
assertThat(directedCDResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_C_D_DIRECTED));
final GetElements<EntitySeed, ?> bothDirectedAndUndirectedOp = new GetElements<>(defaultView, seeds);
// Turn off directed / undirected edges only option and check get both the undirected and directed edge
bothDirectedAndUndirectedOp.setIncludeEdges(IncludeEdgeType.ALL);
final Set<Element> bothDirectedAndUndirectedResults = returnElementsFromOperation(store, bothDirectedAndUndirectedOp, new User(), loadIntoMemory);
assertThat(bothDirectedAndUndirectedResults, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_C_D_DIRECTED, ((Element) AccumuloTestData.EDGE_C_D_UNDIRECTED)));
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method shouldGetCorrectEdges.
private void shouldGetCorrectEdges(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
// Query for all edges in set {A0, A23}
final Set<EntitySeed> seeds = new HashSet<>();
seeds.add(AccumuloTestData.SEED_A0);
seeds.add(AccumuloTestData.SEED_A23);
final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY));
// Query for all edges in set {A1} - there shouldn't be any, but we will get the entity for A1
final GetElements<EntitySeed, ?> a1Operation = new GetElements<>(defaultView, AccumuloTestData.SEED_A1_SET);
final Set<Element> a1Results = returnElementsFromOperation(store, a1Operation, new User(), loadIntoMemory);
assertEquals(1, a1Results.size());
assertThat(a1Results, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY));
// Query for all edges in set {A1, A2} - there shouldn't be any edges but will
// get the two entities
final Set<EntitySeed> a1A2Seeds = new HashSet<>();
a1A2Seeds.add(AccumuloTestData.SEED_A1);
a1A2Seeds.add(AccumuloTestData.SEED_A2);
final GetElements<EntitySeed, ?> a1A2Operation = new GetElements<>(defaultView, a1A2Seeds);
final Set<Element> a1A2Results = returnElementsFromOperation(store, a1A2Operation, new User(), loadIntoMemory);
assertEquals(2, a1A2Results.size());
assertThat(a1A2Results, IsCollectionContaining.hasItems(AccumuloTestData.A1_ENTITY, AccumuloTestData.A2_ENTITY));
}
Aggregations