Search in sources :

Example 6 with HBaseProperties

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

the class AddElementsHandlerTest method shouldAddElements.

@Test
public void shouldAddElements() throws OperationException, StoreException, IOException {
    // Given
    final AddElementsHandler handler = new AddElementsHandler();
    final List<Element> elements = createElements();
    final List<Element> elementsWithNull = new ArrayList<>(elements);
    // null should be skipped
    elementsWithNull.add(null);
    final AddElements addElements = new AddElements.Builder().input(elementsWithNull).build();
    final Context context = mock(Context.class);
    final HBaseStore store = mock(HBaseStore.class);
    final HTable table = mock(HTable.class);
    given(store.getTable()).willReturn(table);
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    final int writeBufferSize = 5;
    properties.setWriteBufferSize(writeBufferSize);
    given(store.getProperties()).willReturn(properties);
    given(store.getSchema()).willReturn(SCHEMA);
    // When
    handler.doOperation(addElements, context, store);
    // Then
    final ArgumentCaptor<List<Put>> putsCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(List.class);
    verify(table, times(2)).put(putsCaptor.capture());
    verify(table, times(2)).flushCommits();
    final List<List<Put>> allPuts = putsCaptor.getAllValues();
    assertThat(allPuts).hasSize(2);
    final List<Put> combinedPuts = new ArrayList<>();
    combinedPuts.addAll(allPuts.get(0));
    combinedPuts.addAll(allPuts.get(1));
    final List<Element> expectedElements = new ArrayList<>();
    for (final Element element : elements) {
        expectedElements.add(element);
        if (element instanceof Edge && !((Edge) element).getSource().equals(((Edge) element).getDestination())) {
            expectedElements.add(element);
        }
    }
    final Element[] expectedElementsArr = expectedElements.toArray(new Element[expectedElements.size()]);
    final List<Element> elementsAdded = CellUtil.getElements(combinedPuts, new ElementSerialisation(SCHEMA), false);
    assertEquals(expectedElements.size(), elementsAdded.size());
    assertThat(elementsAdded).contains(expectedElementsArr);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Context(uk.gov.gchq.gaffer.store.Context) ArgumentCaptor(org.mockito.ArgumentCaptor) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HTable(org.apache.hadoop.hbase.client.HTable) Put(org.apache.hadoop.hbase.client.Put) ElementSerialisation(uk.gov.gchq.gaffer.hbasestore.serialisation.ElementSerialisation) ArrayList(java.util.ArrayList) List(java.util.List) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 7 with HBaseProperties

use of uk.gov.gchq.gaffer.hbasestore.HBaseProperties 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 8 with HBaseProperties

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

the class TableUtilsTest method shouldFailTableValidationWhenTableDoesntHaveCoprocessor.

@Test
public void shouldFailTableValidationWhenTableDoesntHaveCoprocessor() throws Exception {
    // Given
    final SingleUseMiniHBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().aggregateFunction(new StringConcat()).clazz(String.class).build()).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    final HBaseProperties props = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    store.initialise(GRAPH_ID, schema, props);
    // Remove coprocessor
    final TableName tableName = store.getTableName();
    try (final Admin admin = store.getConnection().getAdmin()) {
        final HTableDescriptor descriptor = admin.getTableDescriptor(tableName);
        descriptor.removeCoprocessor(GafferCoprocessor.class.getName());
        admin.modifyTable(tableName, descriptor);
    } catch (final StoreException | IOException e) {
        throw new RuntimeException(e);
    }
    // When / Then
    assertThatExceptionOfType(StoreException.class).isThrownBy(() -> TableUtils.ensureTableExists(store)).extracting("message").isNotNull();
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) StoreException(uk.gov.gchq.gaffer.store.StoreException) TableName(org.apache.hadoop.hbase.TableName) GafferCoprocessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.GafferCoprocessor) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) Test(org.junit.jupiter.api.Test)

Aggregations

HBaseProperties (uk.gov.gchq.gaffer.hbasestore.HBaseProperties)8 Test (org.junit.jupiter.api.Test)6 HBaseStore (uk.gov.gchq.gaffer.hbasestore.HBaseStore)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 SingleUseMiniHBaseStore (uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore)4 HTable (org.apache.hadoop.hbase.client.HTable)3 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)3 Context (uk.gov.gchq.gaffer.store.Context)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 JobConf (org.apache.hadoop.mapred.JobConf)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 GafferCoprocessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.GafferCoprocessor)2 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)2 StringConcat (uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat)2