staticvoid test1() throws Exception {
Hashtable<Object, Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // Here and in the other tests it's important to close the server as // calling `thread.interrupt` from assertion may not be enough // (depending on where the blocking call has stuck) try (TestServer server = new NotBindableServer()) {
env.put(Context.PROVIDER_URL, urlTo(server));
server.start(); // Here and in the other tests joining done purely to reduce timing // jitter. Commenting out or removing that should not make the test // incorrect. (ServerSocket can accept connection as soon as it is // bound, not need to call `accept` before that.)
server.starting().join();
assertIncompletion(INFINITY_MILLIS, () -> new InitialDirContext(env));
}
}
staticvoid test2() throws Exception {
Hashtable<Object, Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put("com.sun.jndi.ldap.connect.timeout", String.valueOf(CONNECT_MILLIS)); try (TestServer server = new BindableButNotReadableServer()) {
env.put(Context.PROVIDER_URL, urlTo(server));
server.start();
server.starting().join();
InitialDirContext ctx = new InitialDirContext(env);
SearchControls scl = new SearchControls();
scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
assertIncompletion(INFINITY_MILLIS,
() -> ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl));
}
}
staticvoid test3() throws Exception {
Hashtable<Object, Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); try (TestServer server = new BindableButNotReadableServer()) {
env.put(Context.PROVIDER_URL, urlTo(server));
server.start();
server.starting().join();
InitialDirContext ctx = new InitialDirContext(env);
SearchControls scl = new SearchControls();
scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
assertIncompletion(INFINITY_MILLIS,
() -> ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl));
}
}
// this queue acts both as an exchange point and a barrier
SynchronousQueue<Long> startTime = new SynchronousQueue<>();
Callable<T> wrappedTask = () -> { // by the time this value reaches the "stopwatch" thread it might be // well outdated and that's okay, we will adjust the wait time
startTime.put(System.nanoTime()); return code.call();
};
FutureTask<T> task = new FutureTask<>(wrappedTask); Thread t = newThread(task);
t.start();
finallong startNanos; try {
startNanos = startTime.take(); // (1) wait for the initial time mark
} catch (Throwable e) {
t.interrupt(); throw e;
}
// this queue acts both as an exchange point and a barrier
SynchronousQueue<Long> startTime = new SynchronousQueue<>();
Callable<?> wrappedTask = () -> { // by the time this value reaches the "stopwatch" thread it might be // well outdated and that's okay, we will adjust the wait time
startTime.put(System.nanoTime()); return code.call();
};
FutureTask<?> task = new FutureTask<>(wrappedTask); Thread t = newThread(task);
t.start();
finallong startNanos; try {
startNanos = startTime.take(); // (1) wait for the initial time mark
} catch (Throwable e) {
t.interrupt(); throw e;
}
/* *Adiagnosticaidthatmighthelpwithdebuggingtimeoutissues.Theidea *istocontinuouslymeasureaccuracyandresponsivenessofthesystemthat *runsthistest.Ifthesystemisoverwhelmed(withsomethingelse),it *mightaffectthetestrun.Attheveryleastwewillhavetracesofthat *inthelogs. * *Thisutilitydoesnotautomaticallyscaleuptesttimeouts,itsimply *gathersinformation.
*/ privatestaticvoid startAuxiliaryDiagnosticOutput() {
System.out.printf("Starting diagnostic output (probe)%n"); Thread t = newThread(() -> { for (int i = 0; ; i = ((i % 20) + 1)) { // 500, 1_000, 1_500, ..., 9_500, 10_000, 500, 1_000, ... long expected = i * 500; long start = System.nanoTime(); try {
MILLISECONDS.sleep(expected);
} catch (InterruptedException e) { return;
} long stop = System.nanoTime(); long actual = NANOSECONDS.toMillis(stop - start);
System.out.printf("(probe) expected [ms.]: %s, actual [ms.]: %s%n",
expected, actual);
}
}, "probe");
t.setDaemon(true);
t.start();
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.20Bemerkung:
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.