Search in sources :

Example 1 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.

the class EntityIdSerialiserTest method testCanSerialiseVertex.

@Test
public void testCanSerialiseVertex() throws SerialisationException {
    // Given
    final String testVertex = "TestVertex";
    // When
    final byte[] serialisedVertex = serialiser.serialiseVertex(testVertex);
    final EntityId deserialisedEntityId = serialiser.deserialise(serialisedVertex);
    // Then
    assertEquals(testVertex, deserialisedEntityId.getVertex());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Test(org.junit.jupiter.api.Test)

Example 2 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.

the class EntityIdSerialiserTest method testCanSerialiseEntityId.

@Test
public void testCanSerialiseEntityId() throws SerialisationException {
    // Given
    final EntityId entityId = new EntitySeed("vertex");
    // When
    final byte[] serialisedEntityId = serialiser.serialise(entityId);
    final EntityId deserialisedEntityId = serialiser.deserialise(serialisedEntityId);
    // Then
    assertEquals(entityId, deserialisedEntityId);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Test(org.junit.jupiter.api.Test)

Example 3 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.

the class ElementIdSerialiserTest method testCanSerialiseVertex.

@Test
public void testCanSerialiseVertex() throws SerialisationException {
    // When
    final byte[] serialisedVertex = serialiser.serialiseVertex(TEST_VERTEX);
    final EntityId deserialisedEntityId = (EntityId) serialiser.deserialise(serialisedVertex);
    // Then
    assertEquals(TEST_VERTEX, deserialisedEntityId.getVertex());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Test(org.junit.jupiter.api.Test)

Example 4 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.

the class AccumuloIDBetweenSetsRetrieverTest method shouldDealWithFalsePositives.

private void shouldDealWithFalsePositives(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    final Set<EntityId> seeds = new HashSet<>();
    seeds.add(AccumuloTestData.SEED_A0);
    seeds.add(AccumuloTestData.SEED_A23);
    // positive sensible.
    for (int i = 0; i < 10; i++) {
        seeds.add(new EntitySeed("abc" + i));
    }
    // Need to make sure that the Bloom filter we create has the same size and the same number of hashes as the
    // one that GraphElementsWithStatisticsWithinSetRetriever creates.
    final int numItemsToBeAdded = loadIntoMemory ? seeds.size() : 20;
    if (!loadIntoMemory) {
        store.getProperties().setMaxEntriesForBatchScanner("20");
    }
    // Find something that will give a false positive
    // Need to repeat the logic used in the getGraphElementsWithStatisticsWithinSet() method.
    // Calculate sensible size of filter, aiming for false positive rate of 1 in 10000, with a maximum size of
    // maxBloomFilterToPassToAnIterator bytes.
    int size = (int) (-numItemsToBeAdded * Math.log(0.0001) / Math.pow(Math.log(2.0), 2.0));
    size = Math.min(size, store.getProperties().getMaxBloomFilterToPassToAnIterator());
    // Work out optimal number of hashes to use in Bloom filter based on size of set - optimal number of hashes is
    // (m/n)ln 2 where m is the size of the filter in bits and n is the number of items that will be added to the set.
    final int numHashes = Math.max(1, (int) ((size / numItemsToBeAdded) * Math.log(2)));
    // Create Bloom filter and add seeds to it
    final BloomFilter filter = new BloomFilter(size, numHashes, Hash.MURMUR_HASH);
    for (final EntityId seed : seeds) {
        filter.add(new Key(store.getKeyPackage().getKeyConverter().serialiseVertex(seed.getVertex())));
    }
    // Test random items against it - should only have to shouldRetrieveElementsInRangeBetweenSeeds MAX_SIZE_BLOOM_FILTER / 2 on average before find a
    // false positive (but impose an arbitrary limit to avoid an infinite loop if there's a problem).
    int count = 0;
    int maxNumberOfTries = 50 * store.getProperties().getMaxBloomFilterToPassToAnIterator();
    while (count < maxNumberOfTries) {
        count++;
        if (filter.membershipTest(new Key(("" + count).getBytes()))) {
            break;
        }
    }
    if (count == maxNumberOfTries) {
        fail("Didn't find a false positive");
    }
    // False positive is "" + count so create an edge from seeds to that
    final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("" + count).directed(true).build();
    edge.putProperty(AccumuloPropertyNames.COUNT, 1000000);
    Set<Element> data = new HashSet<>();
    data.add(edge);
    final User user = new User();
    addElements(data, store, user);
    // Now query for all edges in set - shouldn't get the false positive
    GetElementsBetweenSets op = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A0_SET).inputB(seeds).view(defaultView).build();
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    // Check results are as expected
    assertThat(results).hasSize(2).contains(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY);
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element) BloomFilter(org.apache.hadoop.util.bloom.BloomFilter) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.hadoop.util.bloom.Key) HashSet(java.util.HashSet)

Example 5 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.

the class AccumuloIDWithinSetRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.

private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    final Set<EntityId> seeds = new HashSet<>();
    seeds.add(new EntitySeed("C"));
    seeds.add(new EntitySeed("D"));
    final GetElementsWithinSet op = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    // Set undirected edges only option, and query for edges in set {C, D} - should get the undirected edge
    op.setDirectedType(DirectedType.UNDIRECTED);
    final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(results).contains(AccumuloTestData.EDGE_C_D_UNDIRECTED);
    // Set directed edges only option, and query for edges in set {C, D} - should get the directed edge
    final GetElementsWithinSet directedCOop = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    directedCOop.setDirectedType(DirectedType.DIRECTED);
    final Set<Element> directedCDResults = returnElementsFromOperation(store, directedCOop, new User(), loadIntoMemory);
    assertThat(directedCDResults).contains(AccumuloTestData.EDGE_C_D_DIRECTED);
    final GetElementsWithinSet bothDirectedAndUndirectedOp = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
    // Turn off directed / undirected edges only option and check get both the undirected and directed edge
    bothDirectedAndUndirectedOp.setDirectedType(DirectedType.EITHER);
    final Set<Element> bothDirectedAndUndirectedResults = returnElementsFromOperation(store, bothDirectedAndUndirectedOp, new User(), loadIntoMemory);
    assertThat(bothDirectedAndUndirectedResults).contains(AccumuloTestData.EDGE_C_D_DIRECTED, (Element) AccumuloTestData.EDGE_C_D_UNDIRECTED);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElementsWithinSet(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsWithinSet) HashSet(java.util.HashSet)

Aggregations

EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)93 Test (org.junit.jupiter.api.Test)60 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)41 HashSet (java.util.HashSet)22 User (uk.gov.gchq.gaffer.user.User)21 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)15 Entity (uk.gov.gchq.gaffer.data.element.Entity)15 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)15 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)14 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)13 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)13 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)12 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)10 ArrayList (java.util.ArrayList)8 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 Graph (uk.gov.gchq.gaffer.graph.Graph)7 Context (uk.gov.gchq.gaffer.store.Context)7