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));
}
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());
}
Aggregations