use of com.yahoo.vespa.config.TimingValues in project vespa by vespa-engine.
the class JRTConfigRequestBase method created_from_subscription.
@Test
public void created_from_subscription() {
ConfigSubscriber subscriber = new ConfigSubscriber();
JRTConfigSubscription<SimpletypesConfig> sub = new JRTConfigSubscription<>(new ConfigKey<>(SimpletypesConfig.class, configId), subscriber, new ConfigSet(), new TimingValues());
JRTClientConfigRequest request = createReq(sub, Trace.createNew(9));
assertThat(request.getConfigKey().getName(), is(SimpletypesConfig.CONFIG_DEF_NAME));
JRTServerConfigRequest serverRequest = createReq(request.getRequest());
assertTrue(serverRequest.validateParameters());
}
use of com.yahoo.vespa.config.TimingValues in project vespa by vespa-engine.
the class JRTConfigRequestBase method created_from_existing_subscription.
@Test
public void created_from_existing_subscription() {
System.setProperty("VESPA_CONFIG_PROTOCOL_VERSION", getProtocolVersion());
MockConnection connection = new MockConnection(new MockConnection.AbstractResponseHandler() {
@Override
protected void createResponse() {
JRTServerConfigRequest serverRequest = createReq(request);
serverRequest.addOkResponse(createPayload(), currentGeneration, configMd5);
}
});
ConfigSourceSet src = new ConfigSourceSet();
ConfigSubscriber subscriber = new GenericConfigSubscriber(Collections.singletonMap(src, JRTConfigRequester.get(connection, new TimingValues())));
JRTConfigSubscription<SimpletypesConfig> sub = new JRTConfigSubscription<>(new ConfigKey<>(SimpletypesConfig.class, configId), subscriber, src, new TimingValues());
sub.subscribe(120_0000);
assertTrue(sub.nextConfig(120_0000));
sub.close();
JRTClientConfigRequest nextReq = createReq(sub, Trace.createNew());
SimpletypesConfig config = sub.getConfigState().getConfig();
assertThat(nextReq.getRequestConfigMd5(), is(config.getConfigMd5()));
assertThat(nextReq.getRequestGeneration(), is(currentGeneration));
System.setProperty("VESPA_CONFIG_PROTOCOL_VERSION", "");
}
use of com.yahoo.vespa.config.TimingValues in project vespa by vespa-engine.
the class ConfigSetSubscriptionTest method testConfigSubscription.
@Test
public void testConfigSubscription() {
ConfigSubscriber subscriber = new ConfigSubscriber();
ConfigSet configSet = new ConfigSet();
AppConfig.Builder a0builder = new AppConfig.Builder().message("A message, 0").times(88);
configSet.addBuilder("app/0", a0builder);
AppConfig.Builder a1builder = new AppConfig.Builder().message("A message, 1").times(89);
configSet.addBuilder("app/1", a1builder);
ConfigSubscription<AppConfig> c1 = ConfigSubscription.get(new ConfigKey<>(AppConfig.class, "app/0"), subscriber, configSet, new TimingValues());
ConfigSubscription<AppConfig> c2 = ConfigSubscription.get(new ConfigKey<>(AppConfig.class, "app/1"), subscriber, configSet, new TimingValues());
assertTrue(c1.equals(c1));
assertFalse(c1.equals(c2));
}
use of com.yahoo.vespa.config.TimingValues in project vespa by vespa-engine.
the class JRTConfigRequesterTest method testFirstRequestAfterSubscribing.
@Test
public void testFirstRequestAfterSubscribing() {
ConfigSubscriber subscriber = new ConfigSubscriber();
final TimingValues timingValues = getTestTimingValues();
JRTConfigSubscription<SimpletypesConfig> sub = createSubscription(subscriber, timingValues);
final MockConnection connection = new MockConnection();
JRTConfigRequester requester = new JRTConfigRequester(connection, timingValues);
assertThat(requester.getConnectionPool(), is(connection));
requester.request(sub);
final Request request = connection.getRequest();
assertNotNull(request);
assertThat(connection.getNumberOfRequests(), is(1));
JRTServerConfigRequestV3 receivedRequest = JRTServerConfigRequestV3.createFromRequest(request);
assertTrue(receivedRequest.validateParameters());
assertThat(receivedRequest.getTimeout(), is(timingValues.getSubscribeTimeout()));
assertThat(requester.getFatalFailures(), is(0));
assertThat(requester.getTransientFailures(), is(0));
}
use of com.yahoo.vespa.config.TimingValues in project vespa by vespa-engine.
the class JRTConfigRequesterTest method testDelayCalculation.
@Test
public void testDelayCalculation() {
TimingValues defaultTimingValues = new TimingValues();
// Use seed to make tests predictable
Random random = new Random(0);
TimingValues timingValues = new TimingValues(defaultTimingValues, random);
// transientFailures and fatalFailures are not set until after delay has been calculated,
// so 0 is the case for the first failure
int transientFailures = 0;
int fatalFailures = 0;
boolean configured = false;
// First time failure, not configured
long delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.TRANSIENT, transientFailures, fatalFailures, timingValues, configured);
assertThat(delay, is(timingValues.getUnconfiguredDelay()));
transientFailures = 5;
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.TRANSIENT, transientFailures, fatalFailures, timingValues, configured);
assertThat(delay, is((transientFailures + 1) * timingValues.getUnconfiguredDelay()));
transientFailures = 0;
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.FATAL, transientFailures, fatalFailures, timingValues, configured);
assertTrue(delay > (1 - JRTConfigRequester.randomFraction) * timingValues.getFixedDelay());
assertTrue(delay < (1 + JRTConfigRequester.randomFraction) * timingValues.getFixedDelay());
assertThat(delay, is(5462L));
// First time failure, configured
configured = true;
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.TRANSIENT, transientFailures, fatalFailures, timingValues, configured);
assertThat(delay, is(timingValues.getConfiguredErrorDelay()));
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.FATAL, transientFailures, fatalFailures, timingValues, configured);
assertTrue(delay > (1 - JRTConfigRequester.randomFraction) * timingValues.getFixedDelay());
assertTrue(delay < (1 + JRTConfigRequester.randomFraction) * timingValues.getFixedDelay());
assertThat(delay, is(5663L));
// nth time failure, not configured
fatalFailures = 1;
configured = false;
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.TRANSIENT, transientFailures, fatalFailures, timingValues, configured);
assertThat(delay, is(timingValues.getUnconfiguredDelay()));
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.FATAL, transientFailures, fatalFailures, timingValues, configured);
final long l = timingValues.getFixedDelay() + timingValues.getUnconfiguredDelay();
assertTrue(delay > (1 - JRTConfigRequester.randomFraction) * l);
assertTrue(delay < (1 + JRTConfigRequester.randomFraction) * l);
assertThat(delay, is(5377L));
// nth time failure, configured
fatalFailures = 1;
configured = true;
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.TRANSIENT, transientFailures, fatalFailures, timingValues, configured);
assertThat(delay, is(timingValues.getConfiguredErrorDelay()));
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.FATAL, transientFailures, fatalFailures, timingValues, configured);
final long l1 = timingValues.getFixedDelay() + timingValues.getConfiguredErrorDelay();
assertTrue(delay > (1 - JRTConfigRequester.randomFraction) * l1);
assertTrue(delay < (1 + JRTConfigRequester.randomFraction) * l1);
assertThat(delay, is(20851L));
// 1 more than max delay multiplier time failure, configured
fatalFailures = timingValues.getMaxDelayMultiplier() + 1;
configured = true;
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.TRANSIENT, transientFailures, fatalFailures, timingValues, configured);
assertThat(delay, is(timingValues.getConfiguredErrorDelay()));
assertTrue(delay < timingValues.getMaxDelayMultiplier() * timingValues.getConfiguredErrorDelay());
delay = JRTConfigRequester.calculateFailedRequestDelay(ErrorType.FATAL, transientFailures, fatalFailures, timingValues, configured);
final long l2 = timingValues.getFixedDelay() + timingValues.getMaxDelayMultiplier() * timingValues.getConfiguredErrorDelay();
assertTrue(delay > (1 - JRTConfigRequester.randomFraction) * l2);
assertTrue(delay < (1 + JRTConfigRequester.randomFraction) * l2);
assertThat(delay, is(163520L));
}
Aggregations