Search in sources :

Example 1 with InternalServerException

use of com.twitter.distributedlog.exceptions.InternalServerException in project distributedlog by twitter.

the class TestStreamOp method testResponseFailedTwice.

@Test(timeout = 60000)
public void testResponseFailedTwice() throws Exception {
    WriteOp writeOp = getWriteOp();
    writeOp.fail(new InternalServerException("test1"));
    writeOp.fail(new InternalServerException("test2"));
    WriteResponse response = Await.result(writeOp.result());
    assertEquals(StatusCode.INTERNAL_SERVER_ERROR, response.getHeader().getCode());
    assertEquals(ResponseUtils.exceptionToHeader(new InternalServerException("test1")), response.getHeader());
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) InternalServerException(com.twitter.distributedlog.exceptions.InternalServerException) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Test(org.junit.Test)

Example 2 with InternalServerException

use of com.twitter.distributedlog.exceptions.InternalServerException in project distributedlog by twitter.

the class TestStreamOp method testResponseSucceededThenFailed.

@Test(timeout = 60000)
public void testResponseSucceededThenFailed() throws Exception {
    AsyncLogWriter writer = mock(AsyncLogWriter.class);
    when(writer.write((LogRecord) any())).thenReturn(Future.value(new DLSN(1, 2, 3)));
    when(writer.getStreamName()).thenReturn("test");
    WriteOp writeOp = getWriteOp();
    writeOp.execute(writer, new Sequencer() {

        public long nextId() {
            return 0;
        }
    }, new Object());
    writeOp.fail(new InternalServerException("test2"));
    WriteResponse response = Await.result(writeOp.result());
    assertEquals(StatusCode.SUCCESS, response.getHeader().getCode());
}
Also used : Sequencer(com.twitter.distributedlog.util.Sequencer) DLSN(com.twitter.distributedlog.DLSN) WriteOp(com.twitter.distributedlog.service.stream.WriteOp) InternalServerException(com.twitter.distributedlog.exceptions.InternalServerException) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) AsyncLogWriter(com.twitter.distributedlog.AsyncLogWriter) Test(org.junit.Test)

Aggregations

InternalServerException (com.twitter.distributedlog.exceptions.InternalServerException)2 WriteOp (com.twitter.distributedlog.service.stream.WriteOp)2 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)2 Test (org.junit.Test)2 AsyncLogWriter (com.twitter.distributedlog.AsyncLogWriter)1 DLSN (com.twitter.distributedlog.DLSN)1 Sequencer (com.twitter.distributedlog.util.Sequencer)1