Search in sources :

Example 1 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class ExportToGafferResultCacheHandlerTest method shouldHandleOperationByDelegatingToAnNewExporter.

@Test
public void shouldHandleOperationByDelegatingToAnNewExporter() throws OperationException {
    // Given
    final List<?> results = Arrays.asList(1, 2, 3);
    final ExportToGafferResultCache export = new ExportToGafferResultCache.Builder().key("key").input(results).build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    final Store cacheStore = mock(Store.class);
    TestStore.mockStore = cacheStore;
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    assertSame(handlerResult, results);
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    verify(cacheStore).execute(opChain.capture(), Mockito.eq(context.getUser()));
    assertEquals(1, opChain.getValue().getOperations().size());
    assertTrue(opChain.getValue().getOperations().get(0) instanceof AddElements);
    final GafferResultCacheExporter exporter = context.getExporter(GafferResultCacheExporter.class);
    assertNotNull(exporter);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.Test)

Example 2 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class GetGafferResultCacheExportHandlerTest method shouldHandleOperationByDelegatingToAnExistingExporter.

@Test
public void shouldHandleOperationByDelegatingToAnExistingExporter() throws OperationException {
    // Given
    final GetGafferResultCacheExport export = new GetGafferResultCacheExport.Builder().key("key").build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final GafferResultCacheExporter exporter = mock(GafferResultCacheExporter.class);
    final CloseableIterable results = new WrappedCloseableIterable<>(Arrays.asList(1, 2, 3));
    given(exporter.get("key")).willReturn(results);
    context.addExporter(exporter);
    final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    verify(exporter).get("key");
    assertSame(results, handlerResult);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 3 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class GetGafferResultCacheExportHandlerTest method shouldHandleOperationByDelegatingToAnNewExporter.

@Test
public void shouldHandleOperationByDelegatingToAnNewExporter() throws OperationException {
    // Given
    final GetGafferResultCacheExport export = new GetGafferResultCacheExport.Builder().key("key").build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    final Store cacheStore = mock(Store.class);
    TestStore.mockStore = cacheStore;
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    assertEquals(0, Iterables.size((Iterable) handlerResult));
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    verify(cacheStore).execute(opChain.capture(), Mockito.eq(context.getUser()));
    assertEquals(1, opChain.getValue().getOperations().size());
    assertTrue(opChain.getValue().getOperations().get(0) instanceof GetEdges);
    final GafferResultCacheExporter exporter = context.getExporter(GafferResultCacheExporter.class);
    assertNotNull(exporter);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 4 with Context

use of uk.gov.gchq.gaffer.store.Context 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 5 with Context

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

Aggregations

Test (org.junit.Test)19 Context (uk.gov.gchq.gaffer.store.Context)19 Store (uk.gov.gchq.gaffer.store.Store)17 Element (uk.gov.gchq.gaffer.data.element.Element)7 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)5 User (uk.gov.gchq.gaffer.user.User)5 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)4 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)4 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)4 CountGroupsHandler (uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler)4 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)3 JobTracker (uk.gov.gchq.gaffer.jobtracker.JobTracker)3 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)2 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)2