Search in sources :

Example 1 with GafferScannerProcessor

use of uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor in project Gaffer by gchq.

the class QueryScannerTest method shouldConstructProcessorsWhenViewIsNull.

@Test
public void shouldConstructProcessorsWhenViewIsNull() throws OperationException, IOException {
    // Given
    final Scan scan = mock(Scan.class);
    given(scan.getAttribute(HBaseStoreConstants.VIEW)).willReturn(null);
    // When
    final List<GafferScannerProcessor> processors = QueryScanner.createProcessors(scan, SCHEMA, serialisation);
    // Then
    assertThat(processors).hasSize(2);
    int i = 0;
    assertTrue(processors.get(i) instanceof StoreAggregationProcessor);
    assertEquals(SCHEMA, ((StoreAggregationProcessor) processors.get(i)).getSchema());
    i++;
    assertTrue(processors.get(i) instanceof ValidationProcessor);
    assertEquals(SCHEMA, ((ValidationProcessor) processors.get(i)).getSchema());
}
Also used : StoreAggregationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.StoreAggregationProcessor) GafferScannerProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor) Scan(org.apache.hadoop.hbase.client.Scan) ValidationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ValidationProcessor) Test(org.junit.jupiter.api.Test)

Example 2 with GafferScannerProcessor

use of uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor 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);
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) ArrayList(java.util.ArrayList) GafferScannerProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor) ArrayList(java.util.ArrayList) List(java.util.List) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Cell(org.apache.hadoop.hbase.Cell) ScannerContext(org.apache.hadoop.hbase.regionserver.ScannerContext) Test(org.junit.jupiter.api.Test)

Example 3 with GafferScannerProcessor

use of uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor in project Gaffer by gchq.

the class StoreScannerTest method shouldConstructProcessors.

@Test
public void shouldConstructProcessors() throws OperationException, IOException {
    // Given
    final Scan scan = mock(Scan.class);
    given(scan.getAttribute(HBaseStoreConstants.VIEW)).willReturn(VIEW.toCompactJson());
    given(scan.getAttribute(HBaseStoreConstants.EXTRA_PROCESSORS)).willReturn(StringUtil.toCsv(ElementDedupeFilterProcessor.class));
    // When
    final List<GafferScannerProcessor> processors = StoreScanner.createProcessors(SCHEMA, serialisation);
    // Then
    assertThat(processors).hasSize(2);
    int i = 0;
    assertTrue(processors.get(i) instanceof StoreAggregationProcessor);
    assertEquals(SCHEMA, ((StoreAggregationProcessor) processors.get(i)).getSchema());
    i++;
    assertTrue(processors.get(i) instanceof ValidationProcessor);
    assertEquals(SCHEMA, ((ValidationProcessor) processors.get(i)).getSchema());
}
Also used : StoreAggregationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.StoreAggregationProcessor) GafferScannerProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor) ElementDedupeFilterProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ElementDedupeFilterProcessor) Scan(org.apache.hadoop.hbase.client.Scan) ValidationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ValidationProcessor) Test(org.junit.jupiter.api.Test)

Example 4 with GafferScannerProcessor

use of uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor in project Gaffer by gchq.

the class StoreScannerTest method shouldConstructProcessorsWithNoAggregation.

@Test
public void shouldConstructProcessorsWithNoAggregation() throws OperationException, IOException {
    // Given
    final Scan scan = mock(Scan.class);
    given(scan.getAttribute(HBaseStoreConstants.VIEW)).willReturn(VIEW.toCompactJson());
    given(scan.getAttribute(HBaseStoreConstants.EXTRA_PROCESSORS)).willReturn(StringUtil.toCsv(ElementDedupeFilterProcessor.class));
    // When
    final List<GafferScannerProcessor> processors = StoreScanner.createProcessors(SCHEMA_NO_AGGREGATION, serialisation);
    // Then
    assertThat(processors).hasSize(1);
    int i = 0;
    assertTrue(processors.get(i) instanceof ValidationProcessor);
    assertEquals(SCHEMA_NO_AGGREGATION, ((ValidationProcessor) processors.get(i)).getSchema());
}
Also used : GafferScannerProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor) ElementDedupeFilterProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ElementDedupeFilterProcessor) Scan(org.apache.hadoop.hbase.client.Scan) ValidationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ValidationProcessor) Test(org.junit.jupiter.api.Test)

Example 5 with GafferScannerProcessor

use of uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor in project Gaffer by gchq.

the class QueryScannerTest method shouldConstructProcessorsWithNoExtras.

@Test
public void shouldConstructProcessorsWithNoExtras() throws OperationException, IOException {
    // Given
    final Scan scan = mock(Scan.class);
    given(scan.getAttribute(HBaseStoreConstants.VIEW)).willReturn(VIEW.toCompactJson());
    given(scan.getAttribute(HBaseStoreConstants.EXTRA_PROCESSORS)).willReturn(null);
    // When
    final List<GafferScannerProcessor> processors = QueryScanner.createProcessors(scan, SCHEMA, serialisation);
    // Then
    assertThat(processors).hasSize(6);
    int i = 0;
    assertTrue(processors.get(i) instanceof GroupFilterProcessor);
    assertEquals(VIEW, ((GroupFilterProcessor) processors.get(i)).getView());
    i++;
    assertTrue(processors.get(i) instanceof StoreAggregationProcessor);
    assertEquals(SCHEMA, ((StoreAggregationProcessor) processors.get(i)).getSchema());
    i++;
    assertTrue(processors.get(i) instanceof ValidationProcessor);
    assertEquals(SCHEMA, ((ValidationProcessor) processors.get(i)).getSchema());
    i++;
    assertTrue(processors.get(i) instanceof PreAggregationFilterProcessor);
    assertEquals(VIEW, ((PreAggregationFilterProcessor) processors.get(i)).getView());
    i++;
    assertTrue(processors.get(i) instanceof QueryAggregationProcessor);
    assertEquals(SCHEMA, ((QueryAggregationProcessor) processors.get(i)).getSchema());
    assertEquals(VIEW, ((QueryAggregationProcessor) processors.get(i)).getView());
    i++;
    assertTrue(processors.get(i) instanceof PostAggregationFilterProcessor);
    assertEquals(VIEW, ((PostAggregationFilterProcessor) processors.get(i)).getView());
}
Also used : StoreAggregationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.StoreAggregationProcessor) PostAggregationFilterProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.PostAggregationFilterProcessor) GafferScannerProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor) GroupFilterProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GroupFilterProcessor) Scan(org.apache.hadoop.hbase.client.Scan) ValidationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ValidationProcessor) PreAggregationFilterProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.PreAggregationFilterProcessor) QueryAggregationProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.QueryAggregationProcessor) Test(org.junit.jupiter.api.Test)

Aggregations

GafferScannerProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor)9 ValidationProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ValidationProcessor)8 Test (org.junit.jupiter.api.Test)7 Scan (org.apache.hadoop.hbase.client.Scan)6 StoreAggregationProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.StoreAggregationProcessor)6 ElementDedupeFilterProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.ElementDedupeFilterProcessor)5 GroupFilterProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GroupFilterProcessor)4 PostAggregationFilterProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.PostAggregationFilterProcessor)4 PreAggregationFilterProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.PreAggregationFilterProcessor)4 ArrayList (java.util.ArrayList)3 QueryAggregationProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.QueryAggregationProcessor)3 List (java.util.List)1 Cell (org.apache.hadoop.hbase.Cell)1 InternalScanner (org.apache.hadoop.hbase.regionserver.InternalScanner)1 ScannerContext (org.apache.hadoop.hbase.regionserver.ScannerContext)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 LazyElementCell (uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell)1