Search in sources :

Example 51 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class GafferResultCacheExporterTest method shouldAddResults.

@Test
public void shouldAddResults() throws OperationException, SerialisationException {
    // Given
    final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
    // When
    exporter.add(key, results);
    // Then
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    verify(store).execute(opChain.capture(), Mockito.eq(user));
    assertEquals(1, opChain.getValue().getOperations().size());
    final AddElements addElements = (AddElements) opChain.getValue().getOperations().get(0);
    final List<Element> elements = Lists.newArrayList(addElements.getElements());
    final Object timestamp = elements.get(0).getProperty("timestamp");
    final List<Element> expectedElements = createCachedEdges(timestamp, elements.get(0).getProperty("result"), elements.get(1).getProperty("result"), null);
    assertEquals(expectedElements, elements);
    for (int i = 0; i < elements.size(); i++) {
        if (null == results.get(i)) {
            assertNull(elements.get(i).getProperty("result"));
        } else {
            assertArrayEquals(SERIALISER.serialise(results.get(i)), (byte[]) elements.get(i).getProperty("result"));
        }
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.Test)

Example 52 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class ProxyStoreBasicIT method shouldAddElementsViaAJob.

@Test
public void shouldAddElementsViaAJob() throws Exception {
    // Add elements
    final AddElements add = new AddElements.Builder().elements(DEFAULT_ELEMENTS).build();
    JobDetail jobDetail = graph.executeJob(new OperationChain<>(add), USER);
    // Wait until the job status is not RUNNING
    while (JobStatus.RUNNING.equals(jobDetail.getStatus())) {
        jobDetail = graph.execute(new GetJobDetails.Builder().jobId(jobDetail.getJobId()).build(), USER);
        Thread.sleep(100);
    }
    // Get elements
    final GetElements<EntitySeed, Element> getElements = new GetElements.Builder<EntitySeed, Element>().view(new View.Builder().entity(TestGroups.ENTITY).build()).addSeed(new EntitySeed("1")).build();
    CloseableIterable<Element> results = graph.execute(getElements, USER);
    // Then
    assertEquals(2, Iterables.size(results));
    assertThat(results, hasItem(DEFAULT_ELEMENTS[0]));
    assertThat(results, hasItem(DEFAULT_ELEMENTS[2]));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 53 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class ProxyStoreBasicIT method addDefaultElements.

private void addDefaultElements() throws OperationException {
    final AddElements add = new AddElements.Builder().elements(DEFAULT_ELEMENTS).build();
    graph.execute(add, USER);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements)

Example 54 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldOnlyAggregateVisibilityWhenGroupByIsNull.

@Test
public void shouldOnlyAggregateVisibilityWhenGroupByIsNull() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraph();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "value 3a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "value 4").property(AccumuloPropertyNames.VISIBILITY, PUBLIC_VISIBILITY).build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "value 3a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "value 4").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY).build();
    final Entity entity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "value 3b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "value 4").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY).build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3)), USER);
    // Given
    final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
    // Then
    assertNotNull(results);
    assertEquals(2, results.size());
    final Entity expectedSummarisedEntity = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "value 3a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "value 4").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY + "," + PUBLIC_VISIBILITY).build();
    assertThat(results, IsCollectionContaining.hasItems(expectedSummarisedEntity, entity3));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 55 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldHandleAggregatationWithMultipleCombinations.

@Test
public void shouldHandleAggregatationWithMultipleCombinations() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraphNoVisibility();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, null).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity4 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity5 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").build();
    final Entity entity6 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").build();
    final Entity entity7 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test2a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3, entity4, entity5, entity6, entity7)), USER);
    // Duplicate the entities to check they are aggregated properly
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3, entity4, entity5, entity6, entity7)), USER);
    // Given
    final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy(AccumuloPropertyNames.COLUMN_QUALIFIER, AccumuloPropertyNames.COLUMN_QUALIFIER_2).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
    // Then
    assertNotNull(results);
    assertEquals(4, results.size());
    final Entity expectedEntity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity expectedEntity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity expectedEntity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity expectedEntity4 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test2a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").build();
    assertThat(results, IsCollectionContaining.hasItems(expectedEntity1, expectedEntity2, expectedEntity3, expectedEntity4));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Aggregations

AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)64 Test (org.junit.Test)38 User (uk.gov.gchq.gaffer.user.User)36 Graph (uk.gov.gchq.gaffer.graph.Graph)35 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)31 Element (uk.gov.gchq.gaffer.data.element.Element)30 Edge (uk.gov.gchq.gaffer.data.element.Edge)29 Entity (uk.gov.gchq.gaffer.data.element.Entity)28 ArrayList (java.util.ArrayList)17 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)17 HashSet (java.util.HashSet)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)12 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)9 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)8 Builder (uk.gov.gchq.gaffer.graph.Graph.Builder)7 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)7 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)7 DataOutputStream (java.io.DataOutputStream)6 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)6 Configuration (org.apache.hadoop.conf.Configuration)6