Search in sources :

Example 1 with CountGroupsHandler

use of uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnGroupCountsWithoutLimit.

@Test
public void shouldReturnGroupCountsWithoutLimit() throws OperationException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final CloseableIterable<Element> elements = getElements();
    final Context context = new Context();
    given(countGroups.getLimit()).willReturn(null);
    given(countGroups.getElements()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
    assertEquals(2, counts.getEdgeGroups().size());
    assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
    assertEquals(3, (int) counts.getEdgeGroups().get(GROUP2));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Element(uk.gov.gchq.gaffer.data.element.Element) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 2 with CountGroupsHandler

use of uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnAllGroupCountsWhenLessThanLimit.

@Test
public void shouldReturnAllGroupCountsWhenLessThanLimit() throws OperationException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final CloseableIterable<Element> elements = getElements();
    final Integer limit = 10;
    final Context context = new Context();
    given(countGroups.getLimit()).willReturn(limit);
    given(countGroups.getElements()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
    assertEquals(2, counts.getEdgeGroups().size());
    assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
    assertEquals(3, (int) counts.getEdgeGroups().get(GROUP2));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Element(uk.gov.gchq.gaffer.data.element.Element) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 3 with CountGroupsHandler

use of uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler in project Gaffer by gchq.

the class Store method addCoreOpHandlers.

private void addCoreOpHandlers() {
    // Add elements
    addOperationHandler(AddElements.class, getAddElementsHandler());
    // Get Elements
    addOperationHandler(GetElements.class, (OperationHandler) getGetElementsHandler());
    // Get Adjacent
    addOperationHandler(GetAdjacentIds.class, (OperationHandler) getAdjacentIdsHandler());
    // Get All Elements
    addOperationHandler(GetAllElements.class, (OperationHandler) getGetAllElementsHandler());
    // Export
    addOperationHandler(ExportToSet.class, new ExportToSetHandler());
    addOperationHandler(GetSetExport.class, new GetSetExportHandler());
    addOperationHandler(GetExports.class, new GetExportsHandler());
    // Jobs
    if (null != getJobTracker()) {
        addOperationHandler(GetJobDetails.class, new GetJobDetailsHandler());
        addOperationHandler(GetAllJobDetails.class, new GetAllJobDetailsHandler());
        addOperationHandler(GetJobResults.class, new GetJobResultsHandler());
    }
    // Output
    addOperationHandler(ToArray.class, new ToArrayHandler<>());
    addOperationHandler(ToEntitySeeds.class, new ToEntitySeedsHandler());
    addOperationHandler(ToList.class, new ToListHandler<>());
    addOperationHandler(ToMap.class, new ToMapHandler());
    addOperationHandler(ToCsv.class, new ToCsvHandler());
    addOperationHandler(ToSet.class, new ToSetHandler<>());
    addOperationHandler(ToStream.class, new ToStreamHandler<>());
    addOperationHandler(ToVertices.class, new ToVerticesHandler());
    if (null != CacheServiceLoader.getService()) {
        // Named operation
        addOperationHandler(NamedOperation.class, new NamedOperationHandler());
        addOperationHandler(AddNamedOperation.class, new AddNamedOperationHandler());
        addOperationHandler(GetAllNamedOperations.class, new GetAllNamedOperationsHandler());
        addOperationHandler(DeleteNamedOperation.class, new DeleteNamedOperationHandler());
        // Named view
        addOperationHandler(AddNamedView.class, new AddNamedViewHandler());
        addOperationHandler(GetAllNamedViews.class, new GetAllNamedViewsHandler());
        addOperationHandler(DeleteNamedView.class, new DeleteNamedViewHandler());
    }
    // ElementComparison
    addOperationHandler(Max.class, new MaxHandler());
    addOperationHandler(Min.class, new MinHandler());
    addOperationHandler(Sort.class, new SortHandler());
    // OperationChain
    addOperationHandler(OperationChain.class, getOperationChainHandler());
    addOperationHandler(OperationChainDAO.class, getOperationChainHandler());
    // OperationChain validation
    addOperationHandler(ValidateOperationChain.class, new ValidateOperationChainHandler());
    // Walk tracking
    addOperationHandler(GetWalks.class, new GetWalksHandler());
    // Other
    addOperationHandler(GenerateElements.class, new GenerateElementsHandler<>());
    addOperationHandler(GenerateObjects.class, new GenerateObjectsHandler<>());
    addOperationHandler(Validate.class, new ValidateHandler());
    addOperationHandler(Count.class, new CountHandler());
    addOperationHandler(CountGroups.class, new CountGroupsHandler());
    addOperationHandler(Limit.class, new LimitHandler());
    addOperationHandler(DiscardOutput.class, new DiscardOutputHandler());
    addOperationHandler(GetSchema.class, new GetSchemaHandler());
    addOperationHandler(uk.gov.gchq.gaffer.operation.impl.Map.class, new MapHandler());
    addOperationHandler(If.class, new IfHandler());
    addOperationHandler(While.class, new WhileHandler());
    addOperationHandler(ForEach.class, new ForEachHandler());
    addOperationHandler(ToSingletonList.class, new ToSingletonListHandler());
    addOperationHandler(Reduce.class, new ReduceHandler());
    addOperationHandler(Join.class, new JoinHandler());
    addOperationHandler(CancelScheduledJob.class, new CancelScheduledJobHandler());
    // Context variables
    addOperationHandler(SetVariable.class, new SetVariableHandler());
    addOperationHandler(GetVariable.class, new GetVariableHandler());
    addOperationHandler(GetVariables.class, new GetVariablesHandler());
    // Function
    addOperationHandler(Filter.class, new FilterHandler());
    addOperationHandler(Transform.class, new TransformHandler());
    addOperationHandler(Aggregate.class, new AggregateHandler());
    // GraphLibrary Adds
    if (null != getGraphLibrary() && !(getGraphLibrary() instanceof NoGraphLibrary)) {
        addOperationHandler(AddSchemaToLibrary.class, new AddSchemaToLibraryHandler());
        addOperationHandler(AddStorePropertiesToLibrary.class, new AddStorePropertiesToLibraryHandler());
    }
    addOperationHandler(GetTraits.class, new GetTraitsHandler());
}
Also used : ValidateOperationChainHandler(uk.gov.gchq.gaffer.store.operation.handler.ValidateOperationChainHandler) ExportToSetHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.ExportToSetHandler) DeleteNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedOperationHandler) AggregateHandler(uk.gov.gchq.gaffer.store.operation.handler.function.AggregateHandler) CancelScheduledJobHandler(uk.gov.gchq.gaffer.store.operation.handler.job.CancelScheduledJobHandler) GetVariableHandler(uk.gov.gchq.gaffer.store.operation.handler.GetVariableHandler) ToVerticesHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToVerticesHandler) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler) DeleteNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedOperationHandler) NamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.NamedOperationHandler) ReduceHandler(uk.gov.gchq.gaffer.store.operation.handler.ReduceHandler) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) FilterHandler(uk.gov.gchq.gaffer.store.operation.handler.function.FilterHandler) GetSetExportHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.GetSetExportHandler) SortHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.SortHandler) AddStorePropertiesToLibraryHandler(uk.gov.gchq.gaffer.store.operation.handler.AddStorePropertiesToLibraryHandler) GetJobResultsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetJobResultsHandler) DiscardOutputHandler(uk.gov.gchq.gaffer.store.operation.handler.DiscardOutputHandler) LimitHandler(uk.gov.gchq.gaffer.store.operation.handler.LimitHandler) GetVariablesHandler(uk.gov.gchq.gaffer.store.operation.handler.GetVariablesHandler) ToEntitySeedsHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToEntitySeedsHandler) ToMapHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToMapHandler) SetVariableHandler(uk.gov.gchq.gaffer.store.operation.handler.SetVariableHandler) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) TransformHandler(uk.gov.gchq.gaffer.store.operation.handler.function.TransformHandler) MinHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.MinHandler) GetJobDetailsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetJobDetailsHandler) WhileHandler(uk.gov.gchq.gaffer.store.operation.handler.WhileHandler) AddNamedViewHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedViewHandler) GetTraitsHandler(uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler) ValidateHandler(uk.gov.gchq.gaffer.store.operation.handler.ValidateHandler) GetSchemaHandler(uk.gov.gchq.gaffer.store.operation.handler.GetSchemaHandler) ForEachHandler(uk.gov.gchq.gaffer.store.operation.handler.ForEachHandler) ToSingletonListHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToSingletonListHandler) GetAllJobDetailsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetAllJobDetailsHandler) GetAllNamedViewsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedViewsHandler) MapHandler(uk.gov.gchq.gaffer.store.operation.handler.MapHandler) ToMapHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToMapHandler) ToCsvHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToCsvHandler) GetExportsHandler(uk.gov.gchq.gaffer.store.operation.handler.export.GetExportsHandler) JoinHandler(uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler) AddSchemaToLibraryHandler(uk.gov.gchq.gaffer.store.operation.handler.AddSchemaToLibraryHandler) DeleteNamedViewHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedViewHandler) MaxHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.MaxHandler) IfHandler(uk.gov.gchq.gaffer.store.operation.handler.IfHandler) GetWalksHandler(uk.gov.gchq.gaffer.store.operation.handler.GetWalksHandler) GetAllNamedOperationsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedOperationsHandler) CountHandler(uk.gov.gchq.gaffer.store.operation.handler.CountHandler) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler)

Example 4 with CountGroupsHandler

use of uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnGroupCountsUpToLimit.

@Test
public void shouldReturnGroupCountsUpToLimit() throws OperationException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final CloseableIterable<Element> elements = getElements();
    final Integer limit = 3;
    final Context context = new Context();
    given(countGroups.getLimit()).willReturn(limit);
    given(countGroups.getElements()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertTrue(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(2, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Element(uk.gov.gchq.gaffer.data.element.Element) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 5 with CountGroupsHandler

use of uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnNoCountsIfElementsAreNull.

@Test
public void shouldReturnNoCountsIfElementsAreNull() throws OperationException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final Context context = new Context();
    given(countGroups.getElements()).willReturn(null);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(0, counts.getEntityGroups().size());
    assertEquals(0, counts.getEdgeGroups().size());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Aggregations

CountGroupsHandler (uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler)6 Test (org.junit.Test)4 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)4 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)4 Context (uk.gov.gchq.gaffer.store.Context)4 Store (uk.gov.gchq.gaffer.store.Store)4 Element (uk.gov.gchq.gaffer.data.element.Element)3 ExportToSetHandler (uk.gov.gchq.gaffer.store.operation.handler.export.set.ExportToSetHandler)2 GetSetExportHandler (uk.gov.gchq.gaffer.store.operation.handler.export.set.GetSetExportHandler)2 Test (org.junit.jupiter.api.Test)1 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 NoGraphLibrary (uk.gov.gchq.gaffer.store.library.NoGraphLibrary)1 OperationDeclaration (uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclaration)1 OperationDeclarations (uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclarations)1 AddSchemaToLibraryHandler (uk.gov.gchq.gaffer.store.operation.handler.AddSchemaToLibraryHandler)1 AddStorePropertiesToLibraryHandler (uk.gov.gchq.gaffer.store.operation.handler.AddStorePropertiesToLibraryHandler)1 CountHandler (uk.gov.gchq.gaffer.store.operation.handler.CountHandler)1 DiscardOutputHandler (uk.gov.gchq.gaffer.store.operation.handler.DiscardOutputHandler)1