コード例 #1
0
  @Test
  public void testConsumer() throws Exception {
    EventloopStub eventloop = new EventloopStub();
    eventloop.setTimestamp(
        new LocalDateTime("1970-01-01T00:00:00").toDateTime(DateTimeZone.UTC).getMillis());
    ExecutorService executor = Executors.newCachedThreadPool();
    Path dir = temporaryFolder.newFolder().toPath();
    LogFileSystemImpl fileSystem = new LogFileSystemImpl(eventloop, executor, dir);
    LogManager<String> logManager =
        new LogManagerImpl<>(eventloop, fileSystem, BufferSerializers.stringSerializer());
    new StreamProducers.OfIterator<>(eventloop, Arrays.asList("1", "2", "3").iterator())
        .streamTo(logManager.consumer("p1"));
    eventloop.run();
    eventloop.setTimestamp(
        new LocalDateTime("1970-01-01T00:50:00").toDateTime(DateTimeZone.UTC).getMillis());
    new StreamProducers.OfIterator<>(eventloop, Arrays.asList("4", "5", "6").iterator())
        .streamTo(logManager.consumer("p1"));
    eventloop.run();
    eventloop.setTimestamp(
        new LocalDateTime("1970-01-01T01:50:00").toDateTime(DateTimeZone.UTC).getMillis());
    new StreamProducers.OfIterator<>(eventloop, Arrays.asList("7", "8", "9").iterator())
        .streamTo(logManager.consumer("p1"));
    eventloop.run();
    StreamProducer<String> p1 =
        logManager.producer("p1", new LogFile("1970-01-01_00", 1), 0L, null);

    StreamConsumers.ToList<String> consumerToList = new StreamConsumers.ToList<>(eventloop);
    p1.streamTo(consumerToList);
    eventloop.run();
    System.out.println(consumerToList.getList());
    //		System.out.println(p1.getLogPosition());
  }