use of java.util.logging.Logger in project feign by OpenFeign.
the class FallbackFactoryTest method defaultFallbackFactory_logsAtFineLevel.
@Test
public void defaultFallbackFactory_logsAtFineLevel() {
server.enqueue(new MockResponse().setResponseCode(500));
AtomicBoolean logged = new AtomicBoolean();
Logger logger = new Logger("", null) {
@Override
public void log(Level level, String msg, Throwable thrown) {
logged.set(true);
assertThat(msg).isEqualTo("fallback due to: status 500 reading TestInterface#invoke()");
assertThat(thrown).isInstanceOf(FeignException.class);
}
};
logger.setLevel(Level.FINE);
target(new FallbackFactory.Default<>(() -> "foo", logger)).invoke();
assertThat(logged.get()).isTrue();
}
use of java.util.logging.Logger in project feign by OpenFeign.
the class FallbackFactoryTest method defaultFallbackFactory_doesntLogByDefault.
@Test
public void defaultFallbackFactory_doesntLogByDefault() {
server.enqueue(new MockResponse().setResponseCode(500));
Logger logger = new Logger("", null) {
@Override
public void log(Level level, String msg, Throwable thrown) {
throw new AssertionError("logged eventhough not FINE level");
}
};
target(new FallbackFactory.Default<>(() -> "foo", logger)).invoke();
}
use of java.util.logging.Logger in project jmonkeyengine by jMonkeyEngine.
the class TestChatClient method main.
public static void main(String... args) throws Exception {
// Increate the logging level for networking...
System.out.println("Setting logging to max");
Logger networkLog = Logger.getLogger("com.jme3.network");
networkLog.setLevel(Level.FINEST);
// And we have to tell JUL's handler also
// turn up logging in a very convoluted way
Logger rootLog = Logger.getLogger("");
if (rootLog.getHandlers().length > 0) {
rootLog.getHandlers()[0].setLevel(Level.FINEST);
}
// Note: in JME 3.1 this is generally unnecessary as the server will
// send a message with all server-registered classes.
// TestChatServer.initializeClasses();
// Leaving the call commented out to be illustrative regarding the
// common old pattern.
// Grab a host string from the user
String s = getString(null, "Host Info", "Enter chat host:", "localhost");
if (s == null) {
System.out.println("User cancelled.");
return;
}
// Register a shutdown hook to get a message on the console when the
// app actually finishes
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Chat client is terminating.");
}
});
TestChatClient test = new TestChatClient(s);
test.setVisible(true);
}
use of java.util.logging.Logger in project jmonkeyengine by jMonkeyEngine.
the class TestChatServer method main.
public static void main(String... args) throws Exception {
// Increate the logging level for networking...
System.out.println("Setting logging to max");
Logger networkLog = Logger.getLogger("com.jme3.network");
networkLog.setLevel(Level.FINEST);
// And we have to tell JUL's handler also
// turn up logging in a very convoluted way
Logger rootLog = Logger.getLogger("");
if (rootLog.getHandlers().length > 0) {
rootLog.getHandlers()[0].setLevel(Level.FINEST);
}
TestChatServer chatServer = new TestChatServer();
chatServer.start();
System.out.println("Waiting for connections on port:" + PORT);
// Keep running basically forever
while (chatServer.isRunning) {
synchronized (chatServer) {
chatServer.wait();
}
}
}
use of java.util.logging.Logger in project jna by java-native-access.
the class Kernel32NamedPipeTest method testMultiThreadedNamedPipe.
@Test
public void testMultiThreadedNamedPipe() {
final String pipeName = "\\\\.\\pipe\\" + getCurrentTestName();
final Logger logger = Logger.getLogger(getClass().getName());
final int MAX_BUFFER_SIZE = 1024;
ExecutorService executors = Executors.newFixedThreadPool(2);
try {
Future<?> server = executors.submit(new Runnable() {
@Override
public void run() {
// based on https://msdn.microsoft.com/en-us/library/windows/desktop/aa365588(v=vs.85).aspx
HANDLE hNamedPipe = assertValidHandle("CreateNamedPipe", Kernel32.INSTANCE.CreateNamedPipe(pipeName, // dwOpenMode
WinBase.PIPE_ACCESS_DUPLEX, // dwPipeMode
WinBase.PIPE_TYPE_MESSAGE | WinBase.PIPE_READMODE_MESSAGE | WinBase.PIPE_WAIT, // nMaxInstances,
1, // nOutBufferSize,
MAX_BUFFER_SIZE, // nInBufferSize,
MAX_BUFFER_SIZE, // nDefaultTimeOut,
(int) TimeUnit.SECONDS.toMillis(30L), // lpSecurityAttributes
null));
try {
logger.info("Await client connection");
assertCallSucceeded("ConnectNamedPipe", Kernel32.INSTANCE.ConnectNamedPipe(hNamedPipe, null));
logger.info("Client connected");
byte[] readBuffer = new byte[MAX_BUFFER_SIZE];
IntByReference lpNumberOfBytesRead = new IntByReference(0);
assertCallSucceeded("ReadFile", Kernel32.INSTANCE.ReadFile(hNamedPipe, readBuffer, readBuffer.length, lpNumberOfBytesRead, null));
int readSize = lpNumberOfBytesRead.getValue();
logger.info("Received client data - length=" + readSize);
assertTrue("No data receieved from client", readSize > 0);
IntByReference lpNumberOfBytesWritten = new IntByReference(0);
assertCallSucceeded("WriteFile", Kernel32.INSTANCE.WriteFile(hNamedPipe, readBuffer, readSize, lpNumberOfBytesWritten, null));
logger.info("Echoed client data - length=" + lpNumberOfBytesWritten.getValue());
assertEquals("Mismatched write buffer size", readSize, lpNumberOfBytesWritten.getValue());
// Flush the pipe to allow the client to read the pipe's contents before disconnecting
assertCallSucceeded("FlushFileBuffers", Kernel32.INSTANCE.FlushFileBuffers(hNamedPipe));
logger.info("Disconnecting");
assertCallSucceeded("DisconnectNamedPipe", Kernel32.INSTANCE.DisconnectNamedPipe(hNamedPipe));
logger.info("Disconnected");
} finally {
// clean up
assertCallSucceeded("Named pipe handle close", Kernel32.INSTANCE.CloseHandle(hNamedPipe));
}
}
});
logger.info("Started server - handle=" + server);
Future<?> client = executors.submit(new Runnable() {
@Override
public void run() {
// based on https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx
assertCallSucceeded("WaitNamedPipe", Kernel32.INSTANCE.WaitNamedPipe(pipeName, (int) TimeUnit.SECONDS.toMillis(15L)));
logger.info("Connected to server");
HANDLE hPipe = assertValidHandle("CreateNamedPipe", Kernel32.INSTANCE.CreateFile(pipeName, WinNT.GENERIC_READ | WinNT.GENERIC_WRITE, // no sharing
0, // default security attributes
null, // opens existing pipe
WinNT.OPEN_EXISTING, // default attributes
0, // no template file
null));
try {
IntByReference lpMode = new IntByReference(WinBase.PIPE_READMODE_MESSAGE);
assertCallSucceeded("SetNamedPipeHandleState", Kernel32.INSTANCE.SetNamedPipeHandleState(hPipe, lpMode, null, null));
String expMessage = Thread.currentThread().getName() + " says hello";
byte[] expData = expMessage.getBytes();
IntByReference lpNumberOfBytesWritten = new IntByReference(0);
assertCallSucceeded("WriteFile", Kernel32.INSTANCE.WriteFile(hPipe, expData, expData.length, lpNumberOfBytesWritten, null));
logger.info("Sent hello message");
assertEquals("Mismatched write buffer size", expData.length, lpNumberOfBytesWritten.getValue());
byte[] readBuffer = new byte[MAX_BUFFER_SIZE];
IntByReference lpNumberOfBytesRead = new IntByReference(0);
assertCallSucceeded("ReadFile", Kernel32.INSTANCE.ReadFile(hPipe, readBuffer, readBuffer.length, lpNumberOfBytesRead, null));
int readSize = lpNumberOfBytesRead.getValue();
logger.info("Received server data - length=" + readSize);
assertTrue("No data receieved from server", readSize > 0);
String actMessage = new String(readBuffer, 0, readSize);
assertEquals("Mismatched server data", expMessage, actMessage);
} finally {
// clean up
assertCallSucceeded("Named pipe handle close", Kernel32.INSTANCE.CloseHandle(hPipe));
}
}
});
logger.info("Started client - handle=" + client);
for (Future<?> f : Arrays.asList(client, server)) {
try {
f.get(30L, TimeUnit.SECONDS);
logger.info("Finished " + f);
} catch (Exception e) {
logger.warning(e.getClass().getSimpleName() + " while await completion of " + f + ": " + e.getMessage());
}
}
} finally {
executors.shutdownNow();
}
}
Aggregations