Search in sources :

Example 1 with AddElementsFromSocket

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

the class AddElementsFromSocketHandlerIT method shouldAddElements.

@Test
public void shouldAddElements() throws Exception {
    // Given
    MapStore.resetStaticMap();
    final Graph graph = createGraph();
    final boolean validate = true;
    final boolean skipInvalid = false;
    final String hostname = "localhost";
    final int[] port = new int[1];
    final ServerSocket server = new ServerSocket(0);
    port[0] = server.getLocalPort();
    new Thread(() -> {
        try (final Socket socket = server.accept();
            final OutputStream out = socket.getOutputStream()) {
            out.write(DATA_BYTES);
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }).start();
    final AddElementsFromSocket op = new AddElementsFromSocket.Builder().generator(TestGeneratorImpl.class).parallelism(1).validate(validate).skipInvalidElements(skipInvalid).hostname(hostname).port(port[0]).build();
    // When
    graph.execute(op, new User());
    // Then
    verifyElements(byte[].class, testFileSink, TestBytesGeneratorImpl.class);
}
Also used : User(uk.gov.gchq.gaffer.user.User) OutputStream(java.io.OutputStream) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) Graph(uk.gov.gchq.gaffer.graph.Graph) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) FlinkTest(uk.gov.gchq.gaffer.flink.operation.FlinkTest) Test(org.junit.jupiter.api.Test)

Example 2 with AddElementsFromSocket

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

the class GafferAdderTest method shouldRestartAddElementsIfPauseInIngest.

@Test
public void shouldRestartAddElementsIfPauseInIngest() 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 Element element2 = mock(Element.class);
    final GafferAdder adder = new GafferAdder(op, store);
    // When
    adder.add(element);
    // Then
    final ArgumentCaptor<Runnable> runnableCaptor1 = ArgumentCaptor.forClass(Runnable.class);
    verify(store).runAsync(runnableCaptor1.capture());
    runnableCaptor1.getValue().run();
    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());
    Mockito.reset(store);
    // When
    adder.add(element2);
    // Then
    final ArgumentCaptor<Runnable> runnableCaptor2 = ArgumentCaptor.forClass(Runnable.class);
    verify(store).runAsync(runnableCaptor2.capture());
    runnableCaptor2.getValue().run();
    // As the queue has not been consumed the original elements will still be on the queue.
    expectedQueue.put(element2);
    verify(store).execute(Mockito.eq(new AddElements.Builder().input(expectedQueue).validate(true).skipInvalidElements(false).build()), Mockito.any());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ConsumableBlockingQueue(uk.gov.gchq.gaffer.commonutil.iterable.ConsumableBlockingQueue) Store(uk.gov.gchq.gaffer.store.Store) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 3 with AddElementsFromSocket

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

the class ValidateOperationChainHandlerTest method shouldReturnValidationResultWithErrorsIfOperationChainInvalid.

@Test
public void shouldReturnValidationResultWithErrorsIfOperationChainInvalid() throws OperationException {
    // Given
    final AddElementsFromSocket addElementsFromSocket = new AddElementsFromSocket();
    OperationChain chain = new OperationChain.Builder().first(addElementsFromSocket).build();
    ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
    given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
    ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
    // When
    ValidationResult result = handler.doOperation(validateOperationChain, context, store);
    // Then
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("elementGenerator is required for: AddElementsFromSocket"));
    assertTrue(result.getErrorString().contains("hostname is required for: AddElementsFromSocket"));
}
Also used : ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 4 with AddElementsFromSocket

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

the class AddElementsFromSocketExample method addElementsFromSocket.

public void addElementsFromSocket() {
    // ---------------------------------------------------------
    final AddElementsFromSocket op = new AddElementsFromSocket.Builder().hostname("localhost").port(8080).delimiter(",").generator(ElementGenerator.class).parallelism(1).validate(true).skipInvalidElements(false).build();
    // ---------------------------------------------------------
    showExample(op, null);
}
Also used : AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket)

Example 5 with AddElementsFromSocket

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

the class GafferAdderTest method shouldAddElementsIfInvokeCalledMultipleTimes.

@Test
public void shouldAddElementsIfInvokeCalledMultipleTimes() throws Exception {
    // Given
    final int duplicates = 4;
    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
    for (int i = 0; i < duplicates; i++) {
        adder.add(element);
    }
    // Then
    final ArgumentCaptor<Runnable> runnableCaptor1 = ArgumentCaptor.forClass(Runnable.class);
    verify(store).runAsync(runnableCaptor1.capture());
    assertEquals(1, runnableCaptor1.getAllValues().size());
    runnableCaptor1.getValue().run();
    final ConsumableBlockingQueue<Element> expectedQueue = new ConsumableBlockingQueue<>(MAX_QUEUE_SIZE_VALUE);
    for (int i = 0; i < duplicates; i++) {
        expectedQueue.put(element);
    }
    verify(store).execute(Mockito.eq(new AddElements.Builder().input(expectedQueue).validate(true).skipInvalidElements(false).build()), Mockito.any());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ConsumableBlockingQueue(uk.gov.gchq.gaffer.commonutil.iterable.ConsumableBlockingQueue) Store(uk.gov.gchq.gaffer.store.Store) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) 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