Search in sources :

Example 11 with AssertionFailedError

use of junit.framework.AssertionFailedError in project netty by netty.

the class Http2TestUtil method newVoidPromise.

static ChannelPromise newVoidPromise(final Channel channel) {
    return new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE) {

        @Override
        public ChannelPromise addListener(GenericFutureListener<? extends Future<? super Void>> listener) {
            throw new AssertionFailedError();
        }

        @Override
        public ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
            throw new AssertionFailedError();
        }

        @Override
        public boolean isVoid() {
            return true;
        }

        @Override
        public boolean tryFailure(Throwable cause) {
            channel().pipeline().fireExceptionCaught(cause);
            return true;
        }

        @Override
        public ChannelPromise setFailure(Throwable cause) {
            tryFailure(cause);
            return this;
        }

        @Override
        public ChannelPromise unvoid() {
            ChannelPromise promise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
            promise.addListener(new ChannelFutureListener() {

                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (!future.isSuccess()) {
                        channel().pipeline().fireExceptionCaught(future.cause());
                    }
                }
            });
            return promise;
        }
    };
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) AssertionFailedError(junit.framework.AssertionFailedError) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) ChannelFutureListener(io.netty.channel.ChannelFutureListener)

Example 12 with AssertionFailedError

use of junit.framework.AssertionFailedError in project netty by netty.

the class DefaultHttp2ConnectionDecoderTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    promise = new DefaultChannelPromise(channel);
    when(channel.isActive()).thenReturn(true);
    when(stream.id()).thenReturn(STREAM_ID);
    when(stream.state()).thenReturn(OPEN);
    when(stream.open(anyBoolean())).thenReturn(stream);
    when(pushStream.id()).thenReturn(PUSH_STREAM_ID);
    doAnswer(new Answer<Http2Stream>() {

        @Override
        public Http2Stream answer(InvocationOnMock in) throws Throwable {
            Http2StreamVisitor visitor = in.getArgument(0);
            if (!visitor.visit(stream)) {
                return stream;
            }
            return null;
        }
    }).when(connection).forEachActiveStream(any(Http2StreamVisitor.class));
    when(connection.stream(STREAM_ID)).thenReturn(stream);
    when(connection.streamMayHaveExisted(STREAM_ID)).thenReturn(true);
    when(connection.local()).thenReturn(local);
    when(local.flowController()).thenReturn(localFlow);
    when(encoder.flowController()).thenReturn(remoteFlow);
    when(encoder.frameWriter()).thenReturn(writer);
    when(connection.remote()).thenReturn(remote);
    when(local.reservePushStream(eq(PUSH_STREAM_ID), eq(stream))).thenReturn(pushStream);
    when(remote.reservePushStream(eq(PUSH_STREAM_ID), eq(stream))).thenReturn(pushStream);
    when(ctx.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
    when(ctx.channel()).thenReturn(channel);
    when(ctx.newSucceededFuture()).thenReturn(future);
    when(ctx.newPromise()).thenReturn(promise);
    when(ctx.write(any())).thenReturn(future);
    decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, reader);
    decoder.lifecycleManager(lifecycleManager);
    decoder.frameListener(listener);
    // Simulate receiving the initial settings from the remote endpoint.
    decode().onSettingsRead(ctx, new Http2Settings());
    verify(listener).onSettingsRead(eq(ctx), eq(new Http2Settings()));
    assertTrue(decoder.prefaceReceived());
    verify(encoder).writeSettingsAck(eq(ctx), eq(promise));
    // Simulate receiving the SETTINGS ACK for the initial settings.
    decode().onSettingsAckRead(ctx);
    // Disallow any further flushes now that settings ACK has been sent
    when(ctx.flush()).thenThrow(new AssertionFailedError("forbidden"));
}
Also used : DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AssertionFailedError(junit.framework.AssertionFailedError) Before(org.junit.Before)

Example 13 with AssertionFailedError

use of junit.framework.AssertionFailedError in project netty by netty.

the class DefaultHttp2ConnectionEncoderTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(channel.isActive()).thenReturn(true);
    when(channel.pipeline()).thenReturn(pipeline);
    when(writer.configuration()).thenReturn(writerConfig);
    when(writerConfig.frameSizePolicy()).thenReturn(frameSizePolicy);
    when(frameSizePolicy.maxFrameSize()).thenReturn(64);
    doAnswer(new Answer<ChannelFuture>() {

        @Override
        public ChannelFuture answer(InvocationOnMock in) throws Throwable {
            return ((ChannelPromise) in.getArguments()[2]).setSuccess();
        }
    }).when(writer).writeSettings(eq(ctx), any(Http2Settings.class), any(ChannelPromise.class));
    doAnswer(new Answer<ChannelFuture>() {

        @Override
        public ChannelFuture answer(InvocationOnMock in) throws Throwable {
            ((ByteBuf) in.getArguments()[3]).release();
            return ((ChannelPromise) in.getArguments()[4]).setSuccess();
        }
    }).when(writer).writeGoAway(eq(ctx), anyInt(), anyInt(), any(ByteBuf.class), any(ChannelPromise.class));
    writtenData = new ArrayList<String>();
    writtenPadding = new ArrayList<Integer>();
    when(writer.writeData(eq(ctx), anyInt(), any(ByteBuf.class), anyInt(), anyBoolean(), any(ChannelPromise.class))).then(new Answer<ChannelFuture>() {

        @Override
        public ChannelFuture answer(InvocationOnMock in) throws Throwable {
            // Make sure we only receive stream closure on the last frame and that void promises
            // are used for all writes except the last one.
            ChannelPromise promise = (ChannelPromise) in.getArguments()[5];
            if (streamClosed) {
                fail("Stream already closed");
            } else {
                streamClosed = (Boolean) in.getArguments()[4];
            }
            writtenPadding.add((Integer) in.getArguments()[3]);
            ByteBuf data = (ByteBuf) in.getArguments()[2];
            writtenData.add(data.toString(UTF_8));
            // Release the buffer just as DefaultHttp2FrameWriter does
            data.release();
            // Let the promise succeed to trigger listeners.
            return promise.setSuccess();
        }
    });
    when(writer.writeHeaders(eq(ctx), anyInt(), any(Http2Headers.class), anyInt(), anyShort(), anyBoolean(), anyInt(), anyBoolean(), any(ChannelPromise.class))).then(new Answer<ChannelFuture>() {

        @Override
        public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
            ChannelPromise promise = (ChannelPromise) invocationOnMock.getArguments()[8];
            if (streamClosed) {
                fail("Stream already closed");
            } else {
                streamClosed = (Boolean) invocationOnMock.getArguments()[5];
            }
            return promise.setSuccess();
        }
    });
    payloadCaptor = ArgumentCaptor.forClass(Http2RemoteFlowController.FlowControlled.class);
    doNothing().when(remoteFlow).addFlowControlled(any(Http2Stream.class), payloadCaptor.capture());
    when(ctx.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
    when(ctx.channel()).thenReturn(channel);
    doAnswer(new Answer<ChannelPromise>() {

        @Override
        public ChannelPromise answer(InvocationOnMock in) throws Throwable {
            return newPromise();
        }
    }).when(ctx).newPromise();
    doAnswer(new Answer<ChannelFuture>() {

        @Override
        public ChannelFuture answer(InvocationOnMock in) throws Throwable {
            return newSucceededFuture();
        }
    }).when(ctx).newSucceededFuture();
    when(ctx.flush()).thenThrow(new AssertionFailedError("forbidden"));
    when(channel.alloc()).thenReturn(PooledByteBufAllocator.DEFAULT);
    // Use a server-side connection so we can test server push.
    connection = new DefaultHttp2Connection(true);
    connection.remote().flowController(remoteFlow);
    encoder = new DefaultHttp2ConnectionEncoder(connection, writer);
    encoder.lifecycleManager(lifecycleManager);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) ByteBuf(io.netty.buffer.ByteBuf) FlowControlled(io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) AssertionFailedError(junit.framework.AssertionFailedError) Before(org.junit.Before)

Example 14 with AssertionFailedError

use of junit.framework.AssertionFailedError in project HugeCollections-OLD by peter-lawrey.

the class JSR166TestCase method tearDown.

// Some convenient Integer constants
/**
     * Extra checks that get done for all test cases.
     * <p/>
     * Triggers test case Assert.failure if any thread assertions have Assert.failed,
     * by rethrowing, in the test harness thread, any exception recorded
     * earlier by threadRecordFailure.
     * <p/>
     * Triggers test case Assert.failure if interrupt status is set in the main thread.
     */
@After
public void tearDown() throws Exception {
    Throwable t = threadFailure.getAndSet(null);
    if (t != null) {
        if (t instanceof Error)
            throw (Error) t;
        else if (t instanceof RuntimeException)
            throw (RuntimeException) t;
        else if (t instanceof Exception)
            throw (Exception) t;
        else {
            AssertionFailedError afe = new AssertionFailedError(t.toString());
            afe.initCause(t);
            throw afe;
        }
    }
    if (Thread.interrupted())
        throw new AssertionFailedError("interrupt status set in main thread");
    checkForkJoinPoolThreadLeaks();
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) AssertionFailedError(junit.framework.AssertionFailedError) After(org.junit.After)

Example 15 with AssertionFailedError

use of junit.framework.AssertionFailedError in project HugeCollections-OLD by peter-lawrey.

the class JSR166TestCase method threadUnexpectedException.

/**
     * Records the given exception using {@link #threadRecordFailure},
     * then rethrows the exception, wrapping it in an
     * AssertionFailedError if necessary.
     */
public void threadUnexpectedException(Throwable t) {
    threadRecordFailure(t);
    t.printStackTrace();
    if (t instanceof RuntimeException)
        throw (RuntimeException) t;
    else if (t instanceof Error)
        throw (Error) t;
    else {
        AssertionFailedError afe = new AssertionFailedError("unexpected exception: " + t);
        afe.initCause(t);
        throw afe;
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

AssertionFailedError (junit.framework.AssertionFailedError)787 TestFailureException (org.apache.openejb.test.TestFailureException)503 JMSException (javax.jms.JMSException)336 EJBException (javax.ejb.EJBException)334 RemoteException (java.rmi.RemoteException)268 InitialContext (javax.naming.InitialContext)168 RemoveException (javax.ejb.RemoveException)80 CreateException (javax.ejb.CreateException)77 NamingException (javax.naming.NamingException)65 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)42 Test (org.junit.Test)42 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)41 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)38 CountDownLatch (java.util.concurrent.CountDownLatch)28 EntityManager (javax.persistence.EntityManager)21 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)21 EntityManagerFactory (javax.persistence.EntityManagerFactory)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)16 ConnectionFactory (javax.jms.ConnectionFactory)15