Search in sources :

Example 76 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class AsyncContextTest method testStartFlushCompleteThrow.

@Test
public void testStartFlushCompleteThrow() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
        String request = "GET /ctx/startthrow?flush=true&complete=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "Connection: close\r\n" + "\r\n";
        String responseString = _connector.getResponses(request);
        BufferedReader br = new BufferedReader(new StringReader(responseString));
        assertEquals("HTTP/1.1 200 OK", br.readLine());
        readHeader(br);
        Assert.assertEquals("error servlet", "completeBeforeThrow", br.readLine());
    }
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 77 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class SslContextFactoryTest method testNoKeyConfig.

@Test
public void testNoKeyConfig() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(AbstractLifeCycle.class)) {
        cf.setTrustStorePath("/foo");
        cf.start();
        Assert.fail();
    } catch (IllegalStateException e) {
        Assert.assertThat(e.toString(), Matchers.containsString("IllegalStateException: no valid keystore"));
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Test(org.junit.Test)

Example 78 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class SchedulerTest method testTaskThrowsException.

@Test
public void testTaskThrowsException() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(TimerScheduler.class)) {
        long delay = 500;
        _scheduler.schedule(new Runnable() {

            @Override
            public void run() {
                throw new RuntimeException("Thrown by testTaskThrowsException");
            }
        }, delay, TimeUnit.MILLISECONDS);
        TimeUnit.MILLISECONDS.sleep(2 * delay);
        // Check whether after a task throwing an exception, the scheduler is still working
        final CountDownLatch latch = new CountDownLatch(1);
        _scheduler.schedule(new Runnable() {

            @Override
            public void run() {
                latch.countDown();
            }
        }, delay, TimeUnit.MILLISECONDS);
        Assert.assertTrue(latch.await(2 * delay, TimeUnit.MILLISECONDS));
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 79 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class SweeperTest method testSweepThrows.

@Test
public void testSweepThrows() throws Exception {
    try (StacklessLogging scope = new StacklessLogging(Sweeper.class)) {
        long period = 500;
        final CountDownLatch taskLatch = new CountDownLatch(2);
        Sweeper sweeper = new Sweeper(scheduler, period) {

            @Override
            public void run() {
                super.run();
                taskLatch.countDown();
            }
        };
        sweeper.start();
        final CountDownLatch sweepLatch = new CountDownLatch(2);
        sweeper.offer(new Sweeper.Sweepable() {

            @Override
            public boolean sweep() {
                sweepLatch.countDown();
                throw new NullPointerException("Test exception!");
            }
        });
        Assert.assertTrue(sweepLatch.await(4 * period, TimeUnit.MILLISECONDS));
        Assert.assertTrue(taskLatch.await(4 * period, TimeUnit.MILLISECONDS));
        Assert.assertEquals(1, sweeper.getSize());
        sweeper.stop();
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 80 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class SslContextFactoryTest method testResourceTsResourceKsWrongPW.

@Test
public void testResourceTsResourceKsWrongPW() throws Exception {
    Resource keystoreResource = Resource.newSystemResource("keystore");
    Resource truststoreResource = Resource.newSystemResource("keystore");
    cf.setKeyStoreResource(keystoreResource);
    cf.setTrustStoreResource(truststoreResource);
    cf.setKeyStorePassword("storepwd");
    cf.setKeyManagerPassword("wrong_keypwd");
    cf.setTrustStorePassword("storepwd");
    try (StacklessLogging stackless = new StacklessLogging(AbstractLifeCycle.class)) {
        cf.start();
        Assert.fail();
    } catch (java.security.UnrecoverableKeyException e) {
        Assert.assertThat(e.toString(), Matchers.containsString("UnrecoverableKeyException"));
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Test(org.junit.Test)

Aggregations

StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)143 Test (org.junit.Test)134 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)55 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)51 ArrayList (java.util.ArrayList)46 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)45 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)35 ByteBuffer (java.nio.ByteBuffer)29 IOException (java.io.IOException)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)22 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)21 ServletException (javax.servlet.ServletException)20 CountDownLatch (java.util.concurrent.CountDownLatch)17 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)17 Matchers.containsString (org.hamcrest.Matchers.containsString)17 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)14 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)13 OutputStream (java.io.OutputStream)12 Socket (java.net.Socket)12