/** * Creates exception with a standard message "test timed out after [timeout] [timeUnit]" * * @param timeout the amount of time passed before the test was interrupted * @param timeUnit the time unit for the timeout value */ public TestTimedOutException(long timeout, TimeUnit timeUnit) { super(String.format("test timed out after %d %s", timeout, timeUnit.name().toLowerCase())); this.timeUnit = timeUnit; this.timeout = timeout; }
private static String shortName( TimeUnit unit ) { switch ( unit ) { case NANOSECONDS: return "ns"; case MICROSECONDS: return "μs"; case MILLISECONDS: return "ms"; default: return unit.name().substring( 0, 1 ).toLowerCase(); } }
@Override public void start() throws Exception { log.info("Scheduling reporting of metrics every {} {}", interval, intervalTimeUnit.name().toLowerCase()); // wrap the runnable in a try-catch as uncaught exceptions will prevent subsequent executions executor.scheduleAtFixedRate(() -> { try { reportOnce(); } catch (Exception e) { log.error("Exception in reporting loop", e); } }, interval, interval, intervalTimeUnit); }
@Override public boolean await(long timeout, TimeUnit unit) throws InterruptedException { if (log.isDebugEnabled()) log.debug("Current Latch Count = " + latch.getCount() + "; await for "+ timeout + " " + unit.name() + " appName : " + appName); final long start = log.isDebugEnabled() ? System.currentTimeMillis() : 0; final boolean awaitSuccess = latch.await(timeout, unit); if (log.isDebugEnabled()) log.debug("await success = " + awaitSuccess + " after " + (System.currentTimeMillis() - start) + " msec." + " appName : " + appName + ((evcacheEvent != null) ? " keys : " + evcacheEvent.getCanonicalKeys() : "")); return awaitSuccess; }
@Override public String serialize(int numberOfSpacesToIndent, Delay delay) { StringBuilder output = new StringBuilder(); if (delay != null) { output.append("new Delay(TimeUnit.").append(delay.getTimeUnit().name()).append(", ").append(delay.getValue()).append(")"); } return output.toString(); } }
/** * {@inheritDoc} */ @Override public String toString() { if (isInfinite()) { return "Duration[INFINITE]"; } if (length == 0) { return "Duration[ZERO]"; } return "Duration[length=" + length + ", timeUnit=" + timeUnit.name() + "]"; } }
private static Timer getTimer(String name, String...additionalTags) { String key = className + "." + name + "." + Joiner.on(",").join(additionalTags); return monitors.computeIfAbsent(key, k -> { List<Tag> tagList = getTags(additionalTags); tagList.add(new BasicTag("unit", TimeUnit.MILLISECONDS.name())); return registry.timer(name, tagList); }); }
/** * Returns the {@link ObjectNode} representing the time granularity spec. * <p>Only contains fields with non-default value. * <p>NOTE: here we use {@link ObjectNode} to preserve the insertion order. */ public ObjectNode toJsonObject() { ObjectNode jsonObject = JsonUtils.newObjectNode(); jsonObject.put("name", _name); jsonObject.put("dataType", _dataType.name()); jsonObject.put("timeType", _timeType.name()); if (_timeUnitSize != DEFAULT_TIME_UNIT_SIZE) { jsonObject.put("timeUnitSize", _timeUnitSize); } if (!_timeFormat.equals(DEFAULT_TIME_FORMAT)) { jsonObject.put("timeFormat", _timeFormat); } return jsonObject; }
public static Timer getTimer(String className, String name, String... additionalTags) { Map<String, String> tags = toMap(className, additionalTags); tags.put("unit", TimeUnit.SECONDS.name()); return timers.computeIfAbsent(name, s -> new ConcurrentHashMap<>()).computeIfAbsent(tags, t -> { Id id = registry.createId(name, tags); return PercentileTimer.get(registry, id); }); }
@Override public String serialize(int numberOfSpacesToIndent, TimeToLive timeToLive) { StringBuffer output = new StringBuffer(); if (timeToLive != null) { appendNewLineAndIndent(numberOfSpacesToIndent * INDENT_SIZE, output); if (timeToLive.isUnlimited()) { output.append("TimeToLive.unlimited()"); } else { output.append("TimeToLive.exactly(TimeUnit.").append(timeToLive.getTimeUnit().name()).append(", ").append(timeToLive.getTimeToLive()).append("L)"); } } return output.toString(); }
public void await(int timeout, TimeUnit unit) throws InterruptedException { if (!countDownLatch.await(timeout, unit)) { throw new RuntimeException("Expected Completion within "+ timeout + " " + unit.name() + " but Complete signal was not emitted"); } } }
/** * Creates a new instance of the timer with a unit of milliseconds, * using the {@link ScheduledExecutorService} provided by * the user. * To avoid memory leaks the ScheduledExecutorService * should have the policy to remove tasks from the work queue. * See {@link java.util.concurrent.ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)} */ public StatsTimer(MonitorConfig config, StatsConfig statsConfig, TimeUnit unit, ScheduledExecutorService executor) { super(config, statsConfig, executor, "totalTime", false, Tags.newTag(UNIT, unit.name())); this.timeUnit = unit; startComputingStats(); }
private void printPercentilesSummary() { // we should also consider the case where >1 output messages are from 1 incoming if (histos.size() == 0) { messageSink.accept("No data"); return; } int counter = 0; messageSink.accept("Timings below in " + timeUnit.name()); final StringBuilder sb = new StringBuilder("sourceId "); histos.forEach((id, histogram) -> sb.append(String.format("%12s ", id))); messageSink.accept(sb.toString()); messageSink.accept("count: " + count()); messageSink.accept("50: " + percentiles(counter++)); messageSink.accept("90: " + percentiles(counter++)); messageSink.accept("99: " + percentiles(counter++)); messageSink.accept("99.9: " + percentiles(counter++)); messageSink.accept("99.99: " + percentiles(counter++)); messageSink.accept("99.999: " + percentiles(counter++)); messageSink.accept("99.9999:" + percentiles(counter++)); messageSink.accept("worst: " + percentiles(-1)); }
@SuppressWarnings("deprecation") private static void registerPassivationStoreTransformers_1_2_1_and_1_3_0(ResourceTransformationDescriptionBuilder parent) { ResourceTransformationDescriptionBuilder child = parent.addChildRedirection(PassivationStoreResourceDefinition.INSTANCE.getPathElement(), PathElement.pathElement(EJB3SubsystemModel.CLUSTER_PASSIVATION_STORE)); child.getAttributeBuilder() .setValueConverter(AttributeConverter.Factory.createHardCoded(new ModelNode(true), true), EJB3SubsystemModel.PASSIVATE_EVENTS_ON_REPLICATE) .setValueConverter(AttributeConverter.Factory.createHardCoded(new ModelNode("default"), true), EJB3SubsystemModel.CLIENT_MAPPINGS_CACHE) .setValueConverter(AttributeConverter.Factory.createHardCoded(new ModelNode().set(Long.valueOf(Integer.MAX_VALUE)), true), EJB3SubsystemModel.IDLE_TIMEOUT) .setValueConverter(AttributeConverter.Factory.createHardCoded(new ModelNode().set(TimeUnit.SECONDS.name()), true), EJB3SubsystemModel.IDLE_TIMEOUT_UNIT) ; }
static void toJson(DeploymentOptions obj, java.util.Map<String, Object> json) { if (obj.getConfig() != null) { json.put("config", obj.getConfig()); } if (obj.getExtraClasspath() != null) { JsonArray array = new JsonArray(); obj.getExtraClasspath().forEach(item -> array.add(item)); json.put("extraClasspath", array); } json.put("ha", obj.isHa()); json.put("instances", obj.getInstances()); if (obj.getIsolatedClasses() != null) { JsonArray array = new JsonArray(); obj.getIsolatedClasses().forEach(item -> array.add(item)); json.put("isolatedClasses", array); } if (obj.getIsolationGroup() != null) { json.put("isolationGroup", obj.getIsolationGroup()); } json.put("maxWorkerExecuteTime", obj.getMaxWorkerExecuteTime()); if (obj.getMaxWorkerExecuteTimeUnit() != null) { json.put("maxWorkerExecuteTimeUnit", obj.getMaxWorkerExecuteTimeUnit().name()); } json.put("worker", obj.isWorker()); if (obj.getWorkerPoolName() != null) { json.put("workerPoolName", obj.getWorkerPoolName()); } json.put("workerPoolSize", obj.getWorkerPoolSize()); } }
@Test public void indexKeyForShouldReturnPdxInstanceEnumWhenObjectIsInstanceOfEnum() throws TypeMismatchException { Object keyEnum = TimeUnit.SECONDS; Object keyEnumResult = TypeUtils.indexKeyFor(keyEnum); assertThat(keyEnumResult).isNotNull(); assertThat(keyEnumResult).isInstanceOf(PdxInstanceEnum.class); assertThat(((PdxInstanceEnum) keyEnumResult).getName()).isEqualTo(TimeUnit.SECONDS.name()); assertThat(((PdxInstanceEnum) keyEnumResult).getOrdinal()) .isEqualTo(TimeUnit.SECONDS.ordinal()); assertThat(((PdxInstanceEnum) keyEnumResult).getClassName()) .isEqualTo(TimeUnit.SECONDS.getDeclaringClass().getName()); }
/** * Creates a new instance of the timer. */ BasicTimer(MonitorConfig config, TimeUnit unit, Clock clock) { super(config); final Tag unitTag = Tags.newTag(UNIT, unit.name()); final MonitorConfig unitConfig = config.withAdditionalTag(unitTag); timeUnit = unit; timeUnitNanosFactor = 1.0 / timeUnit.toNanos(1); totalTime = new DoubleCounter(unitConfig.withAdditionalTag(STAT_TOTAL), clock); count = new StepCounter(unitConfig.withAdditionalTag(STAT_COUNT), clock); totalOfSquares = new DoubleCounter(unitConfig.withAdditionalTag(STAT_TOTAL_SQ), clock); max = new DoubleMaxGauge(unitConfig.withAdditionalTag(STAT_MAX), clock); monitors = UnmodifiableList.<Monitor<?>>of(totalTime, count, totalOfSquares, max); }
@Test public void testNonDefaultConfigurationProperties() { final Configuration conf = getDefaultHBaseConfiguration(); final HRegionServer rs = mockRegionServer(conf); final int period = RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_PERIOD_DEFAULT + 1; final long delay = RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_DELAY_DEFAULT + 1L; final String timeUnit = TimeUnit.SECONDS.name(); conf.setInt(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_PERIOD_KEY, period); conf.setLong(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_DELAY_KEY, delay); conf.set(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_TIMEUNIT_KEY, timeUnit); RegionSizeReportingChore chore = new RegionSizeReportingChore(rs); assertEquals(delay, chore.getInitialDelay()); assertEquals(period, chore.getPeriod()); assertEquals(TimeUnit.valueOf(timeUnit), chore.getTimeUnit()); }
@Test public void testNonDefaultConfigurationProperties() { final Configuration conf = getDefaultHBaseConfiguration(); // Override the default values final int period = 60 * 10; final long delay = 30L; final TimeUnit timeUnit = TimeUnit.SECONDS; conf.setInt(FileSystemUtilizationChore.FS_UTILIZATION_CHORE_PERIOD_KEY, period); conf.setLong(FileSystemUtilizationChore.FS_UTILIZATION_CHORE_DELAY_KEY, delay); conf.set(FileSystemUtilizationChore.FS_UTILIZATION_CHORE_TIMEUNIT_KEY, timeUnit.name()); // Verify that the chore reports these non-default values final HRegionServer rs = mockRegionServer(conf); final FileSystemUtilizationChore chore = new FileSystemUtilizationChore(rs); assertEquals(period, chore.getPeriod()); assertEquals(delay, chore.getInitialDelay()); assertEquals(timeUnit, chore.getTimeUnit()); }