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);
}
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;
}
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();
}
Aggregations