Search in sources :

Example 61 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class TestResponseProcessors method testStartSCNExceptionAfterStartCase1.

@Test
public void testStartSCNExceptionAfterStartCase1() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    TestRemoteExceptionHandler remoteExHandler = new TestRemoteExceptionHandler();
    Checkpoint cp = new Checkpoint();
    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    BootstrapStartScnHttpResponseProcessor processor = new BootstrapStartScnHttpResponseProcessor(null, queue, stateMsg, cp, remoteExHandler, null);
    ChannelBuffer buf = getScnResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.channelException(new Exception("dummy exception"));
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.finishResponse();
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.STARTSCN_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No response", true, (null == stateMsg._cp));
}
Also used : DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Checkpoint(com.linkedin.databus.core.Checkpoint) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Example 62 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class DbusEventAppender method run.

@Override
public void run() {
    //append events into buffer serially with varying  window sizes;
    long lastScn = -1;
    _count = 0;
    int dataEventCount = 0;
    int bootstrapCheckpoints = _bootstrapCheckpointPerWindow;
    int maxCount = (int) (_fraction * _events.size());
    for (DbusEvent ev : _events) {
        if (dataEventCount >= maxCount) {
            break;
        }
        long evScn = ev.sequence();
        if (lastScn != evScn) {
            //new window;
            if (lastScn == -1) {
                // Test DDSDBUS-1109 by skipping the start() call. The scn Index should be set for streamEvents() to work correctly
                if (_invokeStartOnBuffer) {
                    _buffer.start(evScn - 1);
                }
                _buffer.startEvents();
                if (_bootstrapCheckpoint != null) {
                    //add the initial checkpoint event to dispatcher's buffer to simulate bootstrap
                    addBootstrapCheckpointEventToBuffer(evScn - 1, dataEventCount, 1);
                }
            } else {
                ++_count;
                if (_callInternalListeners) {
                    if (0 == bootstrapCheckpoints) {
                        _buffer.endEvents(lastScn, _stats);
                    } else {
                        addBootstrapCheckpointEventToBuffer(lastScn, dataEventCount, 1);
                    }
                    --bootstrapCheckpoints;
                } else {
                    if (0 == bootstrapCheckpoints) {
                        _buffer.endEvents(true, lastScn, false, false, _stats);
                    } else {
                        //simulate bootstrap calls (snapshot)
                        addBootstrapCheckpointEventToBuffer(lastScn, dataEventCount, 1);
                    }
                    --bootstrapCheckpoints;
                }
                if (!_bufferReflector.validateBuffer()) {
                    throw new RuntimeException("Buffer validation 1 failed");
                }
                if (bootstrapCheckpoints < 0) {
                    _buffer.startEvents();
                    bootstrapCheckpoints = _bootstrapCheckpointPerWindow;
                }
            }
            if (!_bufferReflector.validateBuffer()) {
                throw new RuntimeException("Buffer validation 2 failed");
            }
            lastScn = evScn;
        }
        dataEventCount = addEventToBuffer(ev, dataEventCount);
        ++_count;
    }
    if ((lastScn != -1) && (maxCount == _events.size())) {
        ++_count;
        _buffer.endEvents(lastScn, _stats);
    }
    _dataEvents = dataEventCount;
}
Also used : DbusEvent(com.linkedin.databus.core.DbusEvent) Checkpoint(com.linkedin.databus.core.Checkpoint)

Example 63 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class RelayEventProducer method getCheckpoint.

protected Checkpoint getCheckpoint(long sinceSCN, MaxSCNReaderWriter scnReaderWriter) {
    long scn = sinceSCN;
    if ((scn < 0) && (_scnReaderWriter != null)) {
        try {
            scn = _scnReaderWriter.getMaxScn();
        } catch (DatabusException e) {
            LOG.info("Cannot read persisted SCN " + e);
            scn = -1;
        }
    }
    // return no cp if unable to read from saved SCN
    if (scn <= 0) {
        return null;
    }
    Checkpoint cp = new Checkpoint();
    cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
    // always have greater than semantic
    cp.setWindowOffset(-1);
    cp.setWindowScn(scn);
    return cp;
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) DatabusException(com.linkedin.databus2.core.DatabusException)

Example 64 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class RelayEventProducer method start.

@Override
public synchronized void start(long sinceSCN) {
    if (_dbusConnection != null && !_dbusConnection.getConnectionStatus().isRunningStatus()) {
        LOG.info("In RelayEventProducer start:  running =" + _dbusConnection.getConnectionStatus().isRunningStatus());
        //translate relay saved scn to client checkpoint
        LOG.info("Requested sinceSCN = " + sinceSCN);
        Checkpoint cp = getCheckpoint(sinceSCN, _scnReaderWriter);
        //check if the relay chaining consumer has been initialized [it could when the leader passes its active buffer]
        if ((cp != null) && (_consumerEventBuffer.getStartSCN() < 0)) {
            //note that the restartScnOffset comes into the picture only iff the buffer is empty
            long savedScn = cp.getWindowScn();
            LOG.info("Checkpoint read = " + savedScn + " restartScnOffset=" + _restartScnOffset);
            long newScn = (savedScn >= _restartScnOffset) ? savedScn - _restartScnOffset : 0;
            cp.setWindowScn(newScn);
            LOG.info("Setting start scn of event buffer to " + cp.getWindowScn());
            _consumerEventBuffer.setStartSCN(cp.getWindowScn());
        }
        LOG.info("Eventbuffer start scn = " + _consumerEventBuffer.getStartSCN());
        //now set the checkpoint in the databus client fetcher
        _dbusConnection.getRelayPullThread().getConnectionState().setCheckpoint(cp);
        //start the connection
        _dbusConnection.start();
        _relayLogger.setDaemon(true);
        _relayLogger.start();
    } else {
        if (_dbusConnection == null) {
            LOG.error("Not started! Connection is null");
        } else {
            LOG.warn("dbusConnection status=" + _dbusConnection.getConnectionStatus().getStatus());
        }
    }
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint)

Example 65 with Checkpoint

use of com.linkedin.databus.core.Checkpoint in project databus by linkedin.

the class TestRelayCommandsLocal method doTestOneDataStreamCommand.

private void doTestOneDataStreamCommand() throws Exception {
    //try to read it
    Checkpoint cp = Checkpoint.createFlexibleCheckpoint();
    String streamRequest = "/stream?sources=100&size=100000&output=json&checkPoint=" + cp.toString();
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, streamRequest);
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    HttpResponse respObj = respHandler.getResponse();
    assertNull("/stream returned unexpected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    if (LOG.isDebugEnabled()) {
        LOG.debug("/stream response:" + new String(respHandler.getReceivedBytes()));
    }
    ObjectMapper objMapper = new ObjectMapper();
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    objMapper.readValue(in, new TypeReference<Map<String, String>>() {
    });
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Checkpoint(com.linkedin.databus.core.Checkpoint) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

Checkpoint (com.linkedin.databus.core.Checkpoint)139 Test (org.testng.annotations.Test)88 ArrayList (java.util.ArrayList)46 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)42 HashMap (java.util.HashMap)42 List (java.util.List)42 IdNamePair (com.linkedin.databus.core.util.IdNamePair)34 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)29 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)27 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)25 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)23 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)22 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)20 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)16 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)16 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)15 IOException (java.io.IOException)15 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)14 Logger (org.apache.log4j.Logger)14 InetSocketAddress (java.net.InetSocketAddress)13