Search in sources :

Example 21 with SetTimeProvider

use of net.openhft.chronicle.core.time.SetTimeProvider in project Chronicle-Queue by OpenHFT.

the class ToEndTest method tailerToEndIncreasesRefCount.

@Test
public void tailerToEndIncreasesRefCount() throws Exception {
    String path = OS.TARGET + "/toEndIncRefCount-" + System.nanoTime();
    IOTools.shallowDeleteDirWithFiles(path);
    SetTimeProvider time = new SetTimeProvider();
    long now = System.currentTimeMillis();
    time.currentTimeMillis(now);
    RollingChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).testBlockSize().rollCycle(RollCycles.TEST_SECONDLY).timeProvider(time).build();
    final SingleChronicleQueueExcerpts.StoreAppender appender = (SingleChronicleQueueExcerpts.StoreAppender) queue.acquireAppender();
    Field storeF1 = SingleChronicleQueueExcerpts.StoreAppender.class.getDeclaredField("store");
    storeF1.setAccessible(true);
    SingleChronicleQueueStore store1 = (SingleChronicleQueueStore) storeF1.get(appender);
    System.out.println(store1);
    appender.writeDocument(wire -> wire.write(() -> "msg").int32(1));
    final SingleChronicleQueueExcerpts.StoreTailer tailer = (SingleChronicleQueueExcerpts.StoreTailer) queue.createTailer();
    System.out.println(tailer);
    tailer.toEnd();
    System.out.println(tailer);
    Field storeF2 = SingleChronicleQueueExcerpts.StoreTailer.class.getDeclaredField("store");
    storeF2.setAccessible(true);
    SingleChronicleQueueStore store2 = (SingleChronicleQueueStore) storeF2.get(tailer);
    // the reference count here is 1, the queue itself
    assertEquals(1, store2.refCount());
}
Also used : Field(java.lang.reflect.Field) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Test(org.junit.Test)

Aggregations

SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)21 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)13 Test (org.junit.Test)10 File (java.io.File)7 MappedFile (net.openhft.chronicle.bytes.MappedFile)5 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)5 RollCycles (net.openhft.chronicle.queue.RollCycles)5 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)4 DocumentContext (net.openhft.chronicle.wire.DocumentContext)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)2 Field (java.lang.reflect.Field)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Future (java.util.concurrent.Future)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Bytes (net.openhft.chronicle.bytes.Bytes)1 MethodReader (net.openhft.chronicle.bytes.MethodReader)1 IORuntimeException (net.openhft.chronicle.core.io.IORuntimeException)1