Search in sources :

Example 11 with HBaseStore

use of uk.gov.gchq.gaffer.hbasestore.HBaseStore in project Gaffer by gchq.

the class GetAdjacentIdsHandlerTest method shouldReturnHBaseRetriever.

@Test
public void shouldReturnHBaseRetriever() throws OperationException, StoreException {
    // Given
    final Iterable<EntityId> ids = mock(Iterable.class);
    final Context context = mock(Context.class);
    final User user = mock(User.class);
    final HBaseStore store = mock(HBaseStore.class);
    final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
    final GetAdjacentIdsHandler handler = new GetAdjacentIdsHandler();
    final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().inputIds(ids).option("option1", "optionValue").inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.INCOMING).directedType(DirectedType.DIRECTED).view(new View()).build();
    given(context.getUser()).willReturn(user);
    final ArgumentCaptor<GetElements> getElementsCaptor = ArgumentCaptor.forClass(GetElements.class);
    given(store.createRetriever(getElementsCaptor.capture(), eq(user), eq(ids), eq(true))).willReturn(hbaseRetriever);
    // When
    final GetAdjacentIdsHandler.ExtractDestinationEntityId result = (GetAdjacentIdsHandler.ExtractDestinationEntityId) handler.doOperation(getAdjacentIds, context, store);
    // Then
    assertSame(hbaseRetriever, result.getInput());
    final GetElements getElements = getElementsCaptor.getValue();
    assertSame(ids, getElements.getInput());
    assertTrue(getElements.getView().getEntities().isEmpty());
    assertEquals(getAdjacentIds.getDirectedType(), getElements.getDirectedType());
    assertEquals(getAdjacentIds.getIncludeIncomingOutGoing(), getElements.getIncludeIncomingOutGoing());
    assertEquals("optionValue", getElements.getOption("option1"));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Test(org.junit.jupiter.api.Test)

Example 12 with HBaseStore

use of uk.gov.gchq.gaffer.hbasestore.HBaseStore in project Gaffer by gchq.

the class HBaseAddElementsFromHdfsJobFactoryTest method getStoreConfiguredWith.

@Override
protected Store getStoreConfiguredWith(final Class<JSONSerialiser> jsonSerialiserClass, final String jsonSerialiserModules, final Boolean strictJson) throws IOException, StoreException {
    final HBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    super.configureStoreProperties(properties, jsonSerialiserClass, jsonSerialiserModules, strictJson);
    store.initialise("graphId", schema, properties);
    final JobConf localConf = createLocalConf();
    final FileSystem fs = FileSystem.getLocal(localConf);
    fs.mkdirs(new Path(outputDir));
    return store;
}
Also used : Path(org.apache.hadoop.fs.Path) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FileSystem(org.apache.hadoop.fs.FileSystem) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) JobConf(org.apache.hadoop.mapred.JobConf)

Example 13 with HBaseStore

use of uk.gov.gchq.gaffer.hbasestore.HBaseStore in project Gaffer by gchq.

the class GetAllElementsHandlerTest method shouldReturnHBaseRetriever.

@Test
public void shouldReturnHBaseRetriever() throws OperationException, StoreException {
    // Given
    final Context context = mock(Context.class);
    final User user = mock(User.class);
    final HBaseStore store = mock(HBaseStore.class);
    final HBaseRetriever<GetAllElements> hbaseRetriever = mock(HBaseRetriever.class);
    final GetAllElementsHandler handler = new GetAllElementsHandler();
    final GetAllElements getElements = new GetAllElements();
    given(context.getUser()).willReturn(user);
    given(store.createRetriever(getElements, user, null, false, ElementDedupeFilterProcessor.class)).willReturn(hbaseRetriever);
    // When
    final HBaseRetriever<GetAllElements> result = (HBaseRetriever<GetAllElements>) handler.doOperation(getElements, context, store);
    // Then
    assertSame(hbaseRetriever, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) HBaseRetriever(uk.gov.gchq.gaffer.hbasestore.retriever.HBaseRetriever) Test(org.junit.jupiter.api.Test)

Example 14 with HBaseStore

use of uk.gov.gchq.gaffer.hbasestore.HBaseStore in project Gaffer by gchq.

the class SampleElementsForSplitPointsHandlerTest method shouldUseTheNumberOfRegionsToCalculateNumSplits.

@Test
public void shouldUseTheNumberOfRegionsToCalculateNumSplits() throws OperationException {
    // Given
    final Integer numSplits = null;
    final List<Element> elements = IntStream.range(0, 30).mapToObj(i -> new Edge(TestGroups.EDGE, "source_" + i, "dest_" + i, true)).collect(Collectors.toList());
    final AbstractSampleElementsForSplitPointsHandler<String, HBaseStore> handler = createHandler();
    final SampleElementsForSplitPoints<String> operation = new SampleElementsForSplitPoints.Builder<String>().input(elements).numSplits(numSplits).build();
    // When
    createHandler().doOperation(operation, new Context(), store);
    // Then
    final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
    verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
    final int expectedNumOfSplits = NUM_TABLE_REGIONS - 1;
    final int expectedElementCount = elements.size() * 2;
    assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, expectedNumOfSplits, expectedElementCount);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StoreException(uk.gov.gchq.gaffer.store.StoreException) Element(uk.gov.gchq.gaffer.data.element.Element) AbstractSampleElementsForSplitPointsHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandlerTest) ArgumentCaptor(org.mockito.ArgumentCaptor) BDDMockito.given(org.mockito.BDDMockito.given) Edge(uk.gov.gchq.gaffer.data.element.Edge) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) TableName(org.apache.hadoop.hbase.TableName) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) AbstractSampleElementsForSplitPointsHandler(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandler) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Admin(org.apache.hadoop.hbase.client.Admin) Context(uk.gov.gchq.gaffer.store.Context) Connection(org.apache.hadoop.hbase.client.Connection) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Context(uk.gov.gchq.gaffer.store.Context) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Element(uk.gov.gchq.gaffer.data.element.Element) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) Edge(uk.gov.gchq.gaffer.data.element.Edge) AbstractSampleElementsForSplitPointsHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 15 with HBaseStore

use of uk.gov.gchq.gaffer.hbasestore.HBaseStore in project Gaffer by gchq.

the class SampleElementsForSplitPointsHandlerTest method shouldCalculateRequiredNumberOfSplitsFromEdges.

@Test
public void shouldCalculateRequiredNumberOfSplitsFromEdges() throws OperationException {
    // Given
    final int numSplits = 3;
    final List<Element> elements = IntStream.range(0, numSplits * 10).mapToObj(i -> new Edge(TestGroups.EDGE, "source_" + i, "dest_" + i, true)).collect(Collectors.toList());
    final AbstractSampleElementsForSplitPointsHandler<String, HBaseStore> handler = createHandler();
    final SampleElementsForSplitPoints<String> operation = new SampleElementsForSplitPoints.Builder<String>().input(elements).numSplits(numSplits).build();
    // When
    createHandler().doOperation(operation, new Context(), createStore());
    // Then
    final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
    verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
    final int expectedElementCount = elements.size() * 2;
    assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, numSplits, expectedElementCount);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StoreException(uk.gov.gchq.gaffer.store.StoreException) Element(uk.gov.gchq.gaffer.data.element.Element) AbstractSampleElementsForSplitPointsHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandlerTest) ArgumentCaptor(org.mockito.ArgumentCaptor) BDDMockito.given(org.mockito.BDDMockito.given) Edge(uk.gov.gchq.gaffer.data.element.Edge) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) TableName(org.apache.hadoop.hbase.TableName) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) AbstractSampleElementsForSplitPointsHandler(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandler) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Admin(org.apache.hadoop.hbase.client.Admin) Context(uk.gov.gchq.gaffer.store.Context) Connection(org.apache.hadoop.hbase.client.Connection) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Context(uk.gov.gchq.gaffer.store.Context) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Element(uk.gov.gchq.gaffer.data.element.Element) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) Edge(uk.gov.gchq.gaffer.data.element.Edge) AbstractSampleElementsForSplitPointsHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandlerTest) Test(org.junit.jupiter.api.Test)

Aggregations

HBaseStore (uk.gov.gchq.gaffer.hbasestore.HBaseStore)15 Test (org.junit.jupiter.api.Test)13 Context (uk.gov.gchq.gaffer.store.Context)12 HBaseProperties (uk.gov.gchq.gaffer.hbasestore.HBaseProperties)6 User (uk.gov.gchq.gaffer.user.User)5 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 List (java.util.List)3 TableName (org.apache.hadoop.hbase.TableName)3 Admin (org.apache.hadoop.hbase.client.Admin)3 HTable (org.apache.hadoop.hbase.client.HTable)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 HBaseRetriever (uk.gov.gchq.gaffer.hbasestore.retriever.HBaseRetriever)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2