Esempio n. 1
0
 static {
   ClassAliasPool.CLASS_ALIASES.addAlias(WireSerializedLambda.class, "SerializedLambda");
   ClassAliasPool.CLASS_ALIASES.addAlias(WireType.class);
   ClassAliasPool.CLASS_ALIASES.addAlias(SerializableFunction.class, "Function");
   ClassAliasPool.CLASS_ALIASES.addAlias(SerializableBiFunction.class, "BiFunction");
   ClassAliasPool.CLASS_ALIASES.addAlias(SerializableConsumer.class, "Consumer");
   ClassAliasPool.CLASS_ALIASES.addAlias(SerializablePredicate.class, "Predicate");
   ClassAliasPool.CLASS_ALIASES.addAlias(SerializableUpdater.class, "Updater");
   ClassAliasPool.CLASS_ALIASES.addAlias(SerializableUpdaterWithArg.class, "UpdaterWithArg");
 }
  @Test
  public void testWriteWhileReading() {
    ClassAliasPool.CLASS_ALIASES.addAlias(Message1.class);
    ClassAliasPool.CLASS_ALIASES.addAlias(Message2.class);

    File path1 = Utils.tempDir("testWriteWhileReading1");
    File path2 = Utils.tempDir("testWriteWhileReading2");

    try (SingleChronicleQueue queue1 =
            SingleChronicleQueueBuilder.binary(path1).testBlockSize().build();
        SingleChronicleQueue queue2 =
            SingleChronicleQueueBuilder.binary(path2).testBlockSize().build()) {
      MethodReader reader2 =
          queue1.createTailer().methodReader(ObjectUtils.printAll(MessageListener.class));
      MessageListener writer2 = queue2.acquireAppender().methodWriter(MessageListener.class);
      MessageListener processor = new MessageProcessor(writer2);
      MethodReader reader1 = queue1.createTailer().methodReader(processor);
      MessageListener writer1 = queue1.acquireAppender().methodWriter(MessageListener.class);

      for (int i = 0; i < 3; i++) {
        // write a message
        writer1.method1(new Message1("hello"));
        writer1.method2(new Message2(234));

        // read those messages
        assertTrue(reader1.readOne());
        assertTrue(reader1.readOne());
        assertFalse(reader1.readOne());

        // read the produced messages
        assertTrue(reader2.readOne());
        assertTrue(reader2.readOne());
        assertFalse(reader2.readOne());
      }
      //            System.out.println(queue1.dump());
    }
  }
 static {
   ClassAliasPool.CLASS_ALIASES.addAlias(TestMarshallable.class);
 }