use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.
the class FilterProcessorTest method shouldSkipDeletedAndRemoveInvalidElements.
@Test
public void shouldSkipDeletedAndRemoveInvalidElements() throws OperationException, SerialisationException {
// Given
final FilterProcessor processor = new FilterProcessor() {
@Override
public boolean test(final LazyElementCell elementCell) {
return elementCell.getElement() instanceof Entity;
}
};
final List<LazyElementCell> lazyCells = CellUtil.getLazyCells(ELEMENTS, serialisation);
final Cell deletedCell = mock(Cell.class);
given(deletedCell.getTypeByte()).willReturn(KeyValue.Type.Delete.getCode());
lazyCells.add(new LazyElementCell(deletedCell, serialisation, false));
// When
final List<LazyElementCell> result = processor.process(lazyCells);
// When / Then
assertThat(result).hasSize(2);
assertEquals(ELEMENTS.get(0), result.get(0).getElement());
assertEquals(deletedCell, result.get(1).getCell());
}
use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.
the class ElementDedupeFilterProcessorTest method shouldOnlyAcceptEdges.
@Test
public void shouldOnlyAcceptEdges() throws OperationException, SerialisationException {
// Given
final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.EITHER);
// When / Then
for (final Element element : ELEMENTS) {
final boolean expectedResult = element instanceof Edge;
final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation);
assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString());
if (null != cells.getSecond()) {
// self elements are not added the other way round
assertEquals(false, processor.test(cells.getSecond()), "Failed for element: " + element.toString());
}
}
}
use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.
the class ElementDedupeFilterProcessorTest method shouldAcceptOnlyEntities.
@Test
public void shouldAcceptOnlyEntities() throws OperationException, SerialisationException {
// Given
final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(true, false, null);
// When / Then
for (final Element element : ELEMENTS) {
final boolean expectedResult = element instanceof Entity;
final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation);
assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString());
if (null != cells.getSecond()) {
// entities and self edges are not added the other way round
assertEquals(expectedResult, processor.test(cells.getSecond()), "Failed for element: " + element.toString());
}
}
}
use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.
the class GafferScannerTest method shouldDelegateToEachProcessor.
@Test
public void shouldDelegateToEachProcessor() throws OperationException, IOException {
// Given
final List<LazyElementCell> lazyCells = CellUtil.getLazyCells(ELEMENTS, serialisation);
final List<Cell> cells = new ArrayList<>();
for (final LazyElementCell lazyElementCell : lazyCells) {
cells.add(lazyElementCell.getCell());
}
final InternalScanner internalScanner = new InternalScanner() {
@Override
public boolean next(final List<Cell> results) throws IOException {
results.addAll(cells);
return true;
}
@Override
public boolean next(final List<Cell> result, final ScannerContext scannerContext) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void close() throws IOException {
throw new UnsupportedOperationException();
}
};
final GafferScannerProcessor processor1 = mock(GafferScannerProcessor.class);
final GafferScannerProcessor processor2 = mock(GafferScannerProcessor.class);
final GafferScanner scanner = new GafferScanner(internalScanner, serialisation, Arrays.asList(processor1, processor2), false) {
};
final List<LazyElementCell> processedCells1 = mock(List.class);
given(processor1.process(Mockito.anyList())).willReturn(processedCells1);
given(processor2.process(processedCells1)).willReturn(lazyCells);
final List<Cell> outputResult = new ArrayList<>();
// When
final boolean result = scanner.next(outputResult, null);
// When / Then
assertTrue(result);
final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
verify(processor1).process(captor.capture());
assertEquals(lazyCells, captor.getValue());
verify(processor2).process(processedCells1);
assertEquals(cells, outputResult);
}
use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.
the class CellUtil method getLazyCells.
public static List<LazyElementCell> getLazyCells(final Iterable<Element> elements, final ElementSerialisation serialisation, final boolean includeMatchedVertex) throws SerialisationException {
final List<LazyElementCell> cells = new ArrayList<>();
for (final Element element : elements) {
final Pair<LazyElementCell, LazyElementCell> cellPair = getLazyCells(element, serialisation, includeMatchedVertex);
cells.add(cellPair.getFirst());
if (null != cellPair.getSecond()) {
cells.add(cellPair.getSecond());
}
}
return cells;
}
Aggregations