Search in sources :

Example 6 with AddElementsFromSocket

use of uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket in project Gaffer by gchq.

the class GafferAdderTest method shouldAddElementsToStore.

@Test
public void shouldAddElementsToStore() throws Exception {
    // Given
    final AddElementsFromSocket op = mock(AddElementsFromSocket.class);
    final Store store = mock(Store.class);
    given(store.getProperties()).willReturn(new StoreProperties());
    given(store.getSchema()).willReturn(new Schema());
    given(op.isValidate()).willReturn(true);
    given(op.isSkipInvalidElements()).willReturn(false);
    given(op.getOption(FlinkConstants.MAX_QUEUE_SIZE)).willReturn(MAX_QUEUE_SIZE_OPTION);
    final Element element = mock(Element.class);
    final GafferAdder adder = new GafferAdder(op, store);
    // When
    adder.add(element);
    // Then
    final ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(store).runAsync(runnableCaptor.capture());
    runnableCaptor.getValue().run();
    ArgumentCaptor<AddElements> opCaptor = ArgumentCaptor.forClass(AddElements.class);
    verify(store).execute(opCaptor.capture(), Mockito.any());
    final ConsumableBlockingQueue<Element> expectedQueue = new ConsumableBlockingQueue<>(MAX_QUEUE_SIZE_VALUE);
    expectedQueue.put(element);
    verify(store).execute(Mockito.eq(new AddElements.Builder().input(expectedQueue).validate(true).skipInvalidElements(false).build()), Mockito.any());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) ConsumableBlockingQueue(uk.gov.gchq.gaffer.commonutil.iterable.ConsumableBlockingQueue) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

AddElementsFromSocket (uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket)6 Test (org.junit.jupiter.api.Test)5 ConsumableBlockingQueue (uk.gov.gchq.gaffer.commonutil.iterable.ConsumableBlockingQueue)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 Store (uk.gov.gchq.gaffer.store.Store)3 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 FlinkTest (uk.gov.gchq.gaffer.flink.operation.FlinkTest)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 ValidateOperationChain (uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)1 ViewValidator (uk.gov.gchq.gaffer.store.schema.ViewValidator)1 User (uk.gov.gchq.gaffer.user.User)1 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)1