Search in sources :

Example 1 with IngestCallback

use of com.alibaba.graphscope.groot.ingestor.IngestCallback in project GraphScope by alibaba.

the class IngestProcessorTest method testIngestProcessor.

@Test
void testIngestProcessor() throws IOException {
    long tailOffset = 50L;
    int queueId = 0;
    Configs configs = Configs.newBuilder().build();
    LogService mockLogService = mock(LogService.class);
    LogReader mockLogReader = mock(LogReader.class);
    when(mockLogService.createReader(queueId, tailOffset + 1)).thenReturn(mockLogReader);
    LogWriter mockLogWriter = mock(LogWriter.class);
    when(mockLogService.createWriter(queueId)).thenReturn(mockLogWriter);
    when(mockLogWriter.append(any())).thenReturn(tailOffset + 3);
    OperationBatch emptyBatch = OperationBatch.newBuilder().build();
    long readSnapshotId = 5L;
    ReadLogEntry readLogEntry1 = new ReadLogEntry(tailOffset + 1, readSnapshotId, emptyBatch);
    ReadLogEntry readLogEntry2 = new ReadLogEntry(tailOffset + 2, readSnapshotId, emptyBatch);
    when(mockLogReader.readNext()).thenReturn(readLogEntry1).thenReturn(readLogEntry2).thenReturn(null);
    BatchSender mockBatchSender = mock(BatchSender.class);
    AtomicLong ingestSnapshotId = new AtomicLong(10L);
    IngestProcessor ingestProcessor = new IngestProcessor(configs, mockLogService, mockBatchSender, queueId, ingestSnapshotId, new MetricsCollector(configs));
    ingestProcessor.setTailOffset(tailOffset);
    ingestProcessor.start();
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(eq(""), eq(queueId), eq(readSnapshotId), eq(tailOffset + 1), any());
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(eq(""), eq(queueId), eq(readSnapshotId), eq(tailOffset + 2), any());
    verify(mockLogReader).close();
    String requestId = "test_ingest_processor";
    IngestCallback mockIngestCallback = mock(IngestCallback.class);
    ingestProcessor.ingestBatch(requestId, emptyBatch, mockIngestCallback);
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(requestId, queueId, ingestSnapshotId.get(), tailOffset + 3, emptyBatch);
    verify(mockIngestCallback, timeout(5000L)).onSuccess(ingestSnapshotId.get());
    ingestProcessor.stop();
    verify(mockLogWriter, timeout(5000L)).close();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) BatchSender(com.alibaba.graphscope.groot.ingestor.BatchSender) ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) IngestProcessor(com.alibaba.graphscope.groot.ingestor.IngestProcessor) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) LogWriter(com.alibaba.graphscope.groot.wal.LogWriter) Configs(com.alibaba.maxgraph.common.config.Configs) LogReader(com.alibaba.graphscope.groot.wal.LogReader) IngestCallback(com.alibaba.graphscope.groot.ingestor.IngestCallback) LogService(com.alibaba.graphscope.groot.wal.LogService) Test(org.junit.jupiter.api.Test)

Example 2 with IngestCallback

use of com.alibaba.graphscope.groot.ingestor.IngestCallback in project GraphScope by alibaba.

the class IngestorRpcTest method testIngestorWriteService.

@Test
void testIngestorWriteService() {
    IngestService ingestService = mock(IngestService.class);
    IngestorWriteService ingestorWriteService = new IngestorWriteService(ingestService);
    WriteIngestorRequest req = WriteIngestorRequest.newBuilder().setQueueId(2).setRequestId("test_req").setOperationBatch(OperationBatch.newBuilder().build().toProto()).build();
    doAnswer(invocation -> {
        IngestCallback callback = invocation.getArgument(3);
        callback.onSuccess(10L);
        return null;
    }).when(ingestService).ingestBatch(eq("test_req"), eq(2), eq(OperationBatch.newBuilder().build()), any());
    StreamObserver<WriteIngestorResponse> observer = mock(StreamObserver.class);
    ingestorWriteService.writeIngestor(req, observer);
    verify(observer).onNext(WriteIngestorResponse.newBuilder().setSnapshotId(10L).build());
    verify(observer).onCompleted();
}
Also used : IngestService(com.alibaba.graphscope.groot.ingestor.IngestService) IngestorWriteService(com.alibaba.graphscope.groot.ingestor.IngestorWriteService) WriteIngestorRequest(com.alibaba.maxgraph.proto.groot.WriteIngestorRequest) WriteIngestorResponse(com.alibaba.maxgraph.proto.groot.WriteIngestorResponse) IngestCallback(com.alibaba.graphscope.groot.ingestor.IngestCallback) Test(org.junit.jupiter.api.Test)

Aggregations

IngestCallback (com.alibaba.graphscope.groot.ingestor.IngestCallback)2 Test (org.junit.jupiter.api.Test)2 BatchSender (com.alibaba.graphscope.groot.ingestor.BatchSender)1 IngestProcessor (com.alibaba.graphscope.groot.ingestor.IngestProcessor)1 IngestService (com.alibaba.graphscope.groot.ingestor.IngestService)1 IngestorWriteService (com.alibaba.graphscope.groot.ingestor.IngestorWriteService)1 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)1 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)1 LogReader (com.alibaba.graphscope.groot.wal.LogReader)1 LogService (com.alibaba.graphscope.groot.wal.LogService)1 LogWriter (com.alibaba.graphscope.groot.wal.LogWriter)1 ReadLogEntry (com.alibaba.graphscope.groot.wal.ReadLogEntry)1 Configs (com.alibaba.maxgraph.common.config.Configs)1 WriteIngestorRequest (com.alibaba.maxgraph.proto.groot.WriteIngestorRequest)1 WriteIngestorResponse (com.alibaba.maxgraph.proto.groot.WriteIngestorResponse)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1