Search in sources :

Example 61 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class GetAllJobDetailsHandlerTest method shouldThrowExceptionIfJobTrackerIsNotConfigured.

@Test
public void shouldThrowExceptionIfJobTrackerIsNotConfigured() {
    // Given
    final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler();
    final GetAllJobDetails operation = mock(GetAllJobDetails.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    given(store.getJobTracker()).willReturn(null);
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(operation, new Context(user), store)).extracting("message").isNotNull();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.jupiter.api.Test)

Example 62 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class GetAllJobDetailsHandlerTest method shouldGetAllJobDetailsByDelegatingToJobTracker.

@Test
public void shouldGetAllJobDetailsByDelegatingToJobTracker() throws OperationException {
    // Given
    final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler();
    final GetAllJobDetails operation = mock(GetAllJobDetails.class);
    final Store store = mock(Store.class);
    final JobTracker jobTracker = mock(JobTracker.class);
    final User user = mock(User.class);
    final CloseableIterable<JobDetail> jobsDetails = mock(CloseableIterable.class);
    given(store.getJobTracker()).willReturn(jobTracker);
    given(jobTracker.getAllJobs(user)).willReturn(jobsDetails);
    // When
    final CloseableIterable<JobDetail> results = handler.doOperation(operation, new Context(user), store);
    // Then
    assertSame(jobsDetails, results);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.jupiter.api.Test)

Example 63 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AddNamedOperationHandlerTest method shouldAddNamedOperationFieldsToNamedOperationDetailCorrectly.

@Test
public void shouldAddNamedOperationFieldsToNamedOperationDetailCorrectly() throws OperationException, CacheOperationFailedException {
    final List<String> readAuths = asList("readAuth1", "readAuth2");
    final List<String> writeAuths = asList("writeAuth1", "writeAuth2");
    OperationChain opChain = new OperationChain.Builder().first(new AddElements()).build();
    addNamedOperation.setOperationChain(opChain);
    addNamedOperation.setScore(2);
    addNamedOperation.setOperationName("testOp");
    addNamedOperation.setLabels(asList("test label"));
    addNamedOperation.setReadAccessRoles(readAuths);
    addNamedOperation.setWriteAccessRoles(writeAuths);
    handler.doOperation(addNamedOperation, context, store);
    final NamedOperationDetail result = mockCache.getNamedOperation("testOp", new User(), EMPTY_ADMIN_AUTH);
    assert cacheContains("testOp");
    assertTrue(result.getScore() == 2);
    assertEquals(asList("test label"), result.getLabels());
    final AccessPredicate expectedReadAccessPredicate = new AccessPredicate(context.getUser(), readAuths);
    assertEquals(expectedReadAccessPredicate, result.getOrDefaultReadAccessPredicate());
    final AccessPredicate expectedWriteAccessPredicate = new AccessPredicate(context.getUser(), writeAuths);
    assertEquals(expectedWriteAccessPredicate, result.getOrDefaultWriteAccessPredicate());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 64 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class RowToElementGeneratorTest method getGraph.

private Graph getGraph(final String elementsSchema, final List<Element> elements) throws OperationException {
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").build()).addSchema(getClass().getResourceAsStream(elementsSchema)).addSchema(getClass().getResourceAsStream("/schema-GraphFrame/types.json")).storeProperties(PROPERTIES).build();
    graph.execute(new AddElements.Builder().input(elements).build(), new User());
    return graph;
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User)

Example 65 with User

use of uk.gov.gchq.gaffer.user.User 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)

Aggregations

User (uk.gov.gchq.gaffer.user.User)378 Test (org.junit.jupiter.api.Test)188 Graph (uk.gov.gchq.gaffer.graph.Graph)155 Element (uk.gov.gchq.gaffer.data.element.Element)143 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)128 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)110 HashSet (java.util.HashSet)109 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)104 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)103 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)98 Edge (uk.gov.gchq.gaffer.data.element.Edge)85 Context (uk.gov.gchq.gaffer.store.Context)85 Entity (uk.gov.gchq.gaffer.data.element.Entity)77 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)57 OperationException (uk.gov.gchq.gaffer.operation.OperationException)52 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)48 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)45 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43