@Test(timeout = 5000) public void readOnlyQueueTailerShouldObserveChangesAfterInitiallyObservedReadLimit() throws Exception { DirectoryUtils.deleteDir(dataDir.toFile()); dataDir.toFile().mkdirs(); try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).testBlockSize().build()) { final StringEvents events = queue.acquireAppender().methodWriterBuilder(StringEvents.class).build(); events.say("hello"); final long readerCapacity = getCurrentQueueFileLength(dataDir); final RecordCounter recordCounter = new RecordCounter(); final ChronicleReader chronicleReader = basicReader().withMessageSink(recordCounter); final ExecutorService executorService = Executors.newSingleThreadExecutor(); Future<?> submit = executorService.submit(chronicleReader::execute); final long expectedReadingDocumentCount = (readerCapacity / ONE_KILOBYTE.length) + 1; int i; for (i = 0; i < expectedReadingDocumentCount; i++) { events.say(new String(ONE_KILOBYTE)); } recordCounter.latch.countDown(); executorService.shutdown(); executorService.awaitTermination(Jvm.isDebug() ? 50 : 5, TimeUnit.SECONDS); submit.get(1, TimeUnit.SECONDS); // #460 read only not supported on windows. if (!OS.isWindows()) assertEquals(expectedReadingDocumentCount, recordCounter.recordCount.get() - 1); } }
System.setProperty("ignoreHeaderCountIfNumberOfExcerptsBehindExceeds", "" + (1 << 12)); if (Jvm.isDebug())
public static boolean isDebugEnabled(Class aClass) { return DEBUG.isEnabled(aClass) || isDebug(); }
public static boolean isDebugEnabled(Class aClass) { return DEBUG.isEnabled(aClass) || isDebug(); }
@NotNull public String toString() { if (Jvm.isDebug()) return "toString() not available while debugging"; @NotNull final Iterator<Map.Entry<K, V>> entries = entrySet().iterator(); if (!entries.hasNext()) return "{}"; @NotNull StringBuilder sb = new StringBuilder(); sb.append('{'); while (entries.hasNext()) { final Map.Entry<K, V> e = entries.next(); final K key = e.getKey(); final V value = e.getValue(); sb.append(key == this ? "(this Map)" : key); sb.append('='); sb.append(value == this ? "(this Map)" : value); if (!entries.hasNext()) return sb.append('}').toString(); sb.append(',').append(' '); } return sb.toString(); }
@Override public void release() throws IllegalStateException { refCount.release(); if (Jvm.isDebug() && refCount.get() == 0) releasedHere = new Error("Released here"); }
public InMemoryLongColumn(TimeSeries timeSeries, String name, BytesLongLookup lookup, long capacity) { super(timeSeries, name); this.lookup = lookup; long value = lookup.sizeFor(capacity); this.bytes = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); }
@NotNull public static LongReference create(BytesStore bytesStore, long offset, int size) { @NotNull LongReference ref = Jvm.isDebug() ? new BinaryLongReference() : new UncheckedLongReference(); ref.bytesStore(bytesStore, offset, size); return ref; }
@Override public void onConsumer(@NotNull WireIn inWire) { if (Jvm.isDebug()) LOG.info("client : bootstrap"); inWire.readDocument(null, d -> { byte remoteIdentifier = d.read(identifierReply).int8(); onConnected(localIdentifier, remoteIdentifier, replication); }); }
@Override public void on(@NotNull Class clazz, @Nullable String message, @NotNull Throwable t) { while (t.getCause() != null && t.getCause() != t) t = t.getCause(); String uri = properties.getProperty(t.getClass().getName()); if (uri == null) { uri = baseURI; String version = System.getProperty("java.version"); if (version.compareTo("1.5") >= 0) { @NotNull String[] parts = version.split("\\."); version = parts[1]; } uri += "+" + version + "+" + URIEncoder.encodeURI(t.toString()) + "+" + URIEncoder.encodeURI(clazz.getSimpleName()); if (message != null) uri += "+" + URIEncoder.encodeURI(message); } try { if (Jvm.isDebug() && Desktop.isDesktopSupported()) Desktop.getDesktop().browse(new URI(uri)); else fallBack.on(clazz, message, t); } catch (Exception e) { fallBack.on(WebExceptionHandler.class, "Failed to open browser", e); } } }
@Override public void on(@NotNull Class clazz, @Nullable String message, @NotNull Throwable t) { while (t.getCause() != null && t.getCause() != t) t = t.getCause(); String uri = properties.getProperty(t.getClass().getName()); if (uri == null) { uri = baseURI; String version = System.getProperty("java.version"); if (version.compareTo("1.5") >= 0) { @NotNull String[] parts = version.split("\\."); version = parts[1]; } uri += "+" + version + "+" + URIEncoder.encodeURI(t.toString()) + "+" + URIEncoder.encodeURI(clazz.getSimpleName()); if (message != null) uri += "+" + URIEncoder.encodeURI(message); } try { if (Jvm.isDebug() && Desktop.isDesktopSupported()) Desktop.getDesktop().browse(new URI(uri)); else fallBack.on(clazz, message, t); } catch (Exception e) { fallBack.on(WebExceptionHandler.class, "Failed to open browser", e); } } }
/** * display the hex data of {@link Bytes} from the position() to the limit() * * @param maxLength limit the number of bytes to be dumped. * @return hex representation of the buffer, from example [0D ,OA, FF] */ @NotNull default String toHexString(long offset, long maxLength) { if (Jvm.isDebug() && Jvm.stackTraceEndsWith("Bytes", 2)) return "Not Available"; long maxLength2 = Math.min(maxLength, readLimit() - offset); @NotNull String ret = BytesInternal.toHexString(this, offset, maxLength2); return maxLength2 < readLimit() - offset ? ret + "... truncated" : ret; }
@Override public void accept(@NotNull EngineReplication.ReplicationEntry e) { long updateTime = Math.max(lastUpdateTime, e.timestamp()); if (updateTime > lastUpdateTime) { hasSentLastUpdateTime = false; lastUpdateTime = updateTime; } if (Jvm.isDebug() && LOG.isDebugEnabled()) { long delay = System.currentTimeMillis() - e.timestamp(); Jvm.debug().on(getClass(), "*****\t\t\t\tSENT : CLIENT :replicatedEntry latency=" + delay + "ms"); } wire.writeNotCompleteDocument(false, wireOut -> wireOut.writeEventName(replicationEvent).typedMarshallable(e)); }
@Override @ForceInline public byte readByte(long offset) { if (Jvm.isDebug()) checkReleased(); return memory.readByte(address + translate(offset)); }
@Override public void ensureCapacity(long capacity) { long cap = lookup.sizeFor(capacity); if (cap > bytes.realCapacity()) { long value = lookup.sizeFor(capacity); BytesStore bytes2 = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); bytes2.write(0, bytes); bytes.release(); bytes = bytes2; } }
@Override public void close() { try { closedHere = Jvm.isDebug() ? new StackTrace("Closed here") : null;
@Override public boolean action() throws InvalidEventHandlerException { long loopStartMS = eventLoop.loopStartMS(); if (loopStartMS <= 0 || loopStartMS == Long.MAX_VALUE) return false; if (loopStartMS == Long.MAX_VALUE - 1) { Jvm.warn().on(getClass(), "Monitoring a task which has finished " + eventLoop); throw new InvalidEventHandlerException(); } long now = Time.currentTimeMillis(); long blockingTimeMS = now - loopStartMS; long blockingInterval = blockingTimeMS / ((monitoryIntervalMs + 1) / 2); if (blockingInterval > lastInterval && !Jvm.isDebug() && eventLoop.isAlive()) { eventLoop.dumpRunningState(eventLoop.name() + " thread has blocked for " + blockingTimeMS + " ms.", // check we are still in the loop. () -> eventLoop.loopStartMS() == loopStartMS); } else { lastInterval = Math.max(1, blockingInterval); } return false; } }
if (Jvm.isDebug()) LOG.info("server : received lastUpdateTime"); final long time = valueIn.int64(); if (Jvm.isDebug() && LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "server : received replicationEvent"); VanillaReplicatedEntry replicatedEntry = vre.get(); valueIn.marshallable(replicatedEntry); if (Jvm.isDebug() && LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "*****\t\t\t\t -> RECEIVED : SERVER : replication latency=" + (System .currentTimeMillis() - replicatedEntry.timestamp()) + "ms "); outWire.writeEventName(bootstrap).typedMarshallable(outBootstrap); if (Jvm.isDebug()) System.out.println("server : received replicationSubscribe");
if (Jvm.isDebug()) LOG.info("server : received lastUpdateTime"); final long time = valueIn.int64(); if (Jvm.isDebug() && LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "server : received replicationEvent"); VanillaReplicatedEntry replicatedEntry = vre.get(); valueIn.marshallable(replicatedEntry); if (Jvm.isDebug() && LOG.isDebugEnabled()) Jvm.debug().on(getClass(), "*****\t\t\t\t -> RECEIVED : SERVER : replication latency=" + (System .currentTimeMillis() - replicatedEntry.timestamp()) + "ms "); if (Jvm.isDebug()) LOG.info("server : received simplebootstrap"); if (mi == null) outWire.writeEventName(bootstrap).typedMarshallable(outBootstrap); if (Jvm.isDebug()) LOG.info("server : received replicationSubscribe");