Search in sources :

Example 11 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest in project vespa by vespa-engine.

the class DelayedResponseTest method testDelayedResponse.

@Test
public void testDelayedResponse() {
    ConfigTester tester = new ConfigTester();
    final long timeout = 20000;
    JRTServerConfigRequest request1 = tester.createRequest("baz", configId, namespace, timeout);
    DelayedResponse delayed1 = new DelayedResponse(request1);
    assertTrue(delayed1.getReturnTime() > System.currentTimeMillis());
    assertTrue(delayed1.getDelay(TimeUnit.MILLISECONDS) > 0);
    assertTrue(delayed1.getDelay(TimeUnit.MILLISECONDS) <= timeout);
    // Just to make sure we do not get requests within the same millisecond
    try {
        Thread.sleep(1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // New request, should have larger delay than the first
    JRTServerConfigRequest request2 = tester.createRequest("baz", configId, namespace, timeout);
    DelayedResponse delayed2 = new DelayedResponse(request2);
    assertTrue("delayed1=" + delayed1.getReturnTime() + ", delayed2=" + delayed2.getReturnTime() + ": delayed2 should be greater than delayed1", delayed2.getReturnTime() > delayed1.getReturnTime());
    // Test compareTo() method
    assertThat(delayed1.compareTo(delayed1), is(0));
    assertThat(delayed1.compareTo(delayed2), is(-1));
    assertThat(delayed2.compareTo(delayed1), is(1));
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest) Test(org.junit.Test)

Example 12 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest in project vespa by vespa-engine.

the class ClientUpdater method sendResponse.

private void sendResponse(RawConfig config) {
    if (config.isError()) {
        statistics.incErrorCount();
    }
    log.log(LogLevel.DEBUG, () -> "Sending response for " + config.getKey() + "," + config.getGeneration());
    DelayQueue<DelayedResponse> responseDelayQueue = delayedResponses.responses();
    log.log(LogLevel.SPAM, () -> "Delayed response queue: " + responseDelayQueue);
    if (responseDelayQueue.size() == 0) {
        log.log(LogLevel.DEBUG, () -> "There exists no matching element on delayed response queue for " + config.getKey());
        return;
    } else {
        log.log(LogLevel.DEBUG, () -> "Delayed response queue has " + responseDelayQueue.size() + " elements");
    }
    DelayedResponse[] responses = responseDelayQueue.toArray(new DelayedResponse[0]);
    boolean found = false;
    for (DelayedResponse response : responses) {
        JRTServerConfigRequest request = response.getRequest();
        if (request.getConfigKey().equals(config.getKey())) {
            if (delayedResponses.remove(response)) {
                found = true;
                log.log(LogLevel.DEBUG, () -> "Call returnOkResponse for " + config.getKey() + "," + config.getGeneration());
                rpcServer.returnOkResponse(request, config);
            } else {
                log.log(LogLevel.INFO, "Could not remove " + config.getKey() + " from delayedResponses queue, already removed");
            }
        }
    }
    if (!found) {
        log.log(LogLevel.DEBUG, () -> "Found no recipient for " + config.getKey() + " in delayed response queue");
    }
    log.log(LogLevel.DEBUG, () -> "Finished updating config for " + config.getKey() + "," + config.getGeneration());
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest)

Aggregations

JRTServerConfigRequest (com.yahoo.vespa.config.protocol.JRTServerConfigRequest)12 Test (org.junit.Test)8 TenantName (com.yahoo.config.provision.TenantName)1 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)1 RawConfig (com.yahoo.vespa.config.RawConfig)1 GetConfigContext (com.yahoo.vespa.config.server.GetConfigContext)1 GetConfigProcessor (com.yahoo.vespa.config.server.rpc.GetConfigProcessor)1 MockRpc (com.yahoo.vespa.config.server.rpc.MockRpc)1 MockTenantProvider (com.yahoo.vespa.config.server.tenant.MockTenantProvider)1 Date (java.util.Date)1 Delayed (java.util.concurrent.Delayed)1 TimeUnit (java.util.concurrent.TimeUnit)1