Search in sources :

Example 1 with RawConfig

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

the class MemoryCacheTest method setup.

@Before
public void setup() {
    ArrayList<String> defContent = new ArrayList<>();
    defContent.add("bar string");
    Slime slime = new Slime();
    slime.setString("bar \"value\"");
    payload = Payload.from(new ConfigPayload(slime));
    slime = new Slime();
    slime.setString("bar \"baz\"");
    payload2 = Payload.from(new ConfigPayload(slime));
    slime = new Slime();
    slime.setString("bar \"value2\"");
    payloadDifferentMd5 = Payload.from(new ConfigPayload(slime));
    config = new RawConfig(configKey, defMd5, payload, configMd5, generation, defContent, Optional.empty());
    config2 = new RawConfig(configKey2, defMd52, payload2, configMd5, generation, defContent, Optional.empty());
    configDifferentMd5 = new RawConfig(configKey, differentDefMd5, payloadDifferentMd5, configMd5, generation, defContent, Optional.empty());
    cacheKey = new ConfigCacheKey(configKey, config.getDefMd5());
    cacheKey2 = new ConfigCacheKey(configKey2, config2.getDefMd5());
    cacheKeyDifferentMd5 = new ConfigCacheKey(configKey, differentDefMd5);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) ArrayList(java.util.ArrayList) Slime(com.yahoo.slime.Slime) RawConfig(com.yahoo.vespa.config.RawConfig) Before(org.junit.Before)

Example 2 with RawConfig

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

the class MemoryCacheTest method basic.

@Test
public void basic() {
    MemoryCache cache = new MemoryCache();
    cache.put(config);
    cache.put(config2);
    assertThat(cache.size(), is(2));
    assertTrue(cache.containsKey(cacheKey));
    assertTrue(cache.containsKey(cacheKey2));
    RawConfig response = cache.get(cacheKey);
    assertNotNull(response);
    assertThat(response.getName(), is(defName));
    assertThat(response.getPayload().toString(), is(payload.toString()));
    assertThat(response.getGeneration(), is(generation));
    response = cache.get(cacheKey2);
    assertNotNull(response);
    assertThat(response.getName(), is(defName2));
    assertThat(response.getPayload().toString(), is(payload2.toString()));
    assertThat(response.getGeneration(), is(generation));
    cache.clear();
}
Also used : RawConfig(com.yahoo.vespa.config.RawConfig) Test(org.junit.Test)

Example 3 with RawConfig

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

the class MemoryCacheTest method testSameConfigNameDifferentMd5.

@Test
public void testSameConfigNameDifferentMd5() {
    MemoryCache cache = new MemoryCache();
    cache.put(config);
    // same name, different defMd5
    cache.put(configDifferentMd5);
    assertThat(cache.size(), is(2));
    assertTrue(cache.containsKey(cacheKey));
    RawConfig response = cache.get(cacheKey);
    assertNotNull(response);
    assertThat(response.getName(), is(defName));
    assertThat(response.getPayload().getData(), is(payload.getData()));
    assertThat(response.getGeneration(), is(generation));
    response = cache.get(cacheKeyDifferentMd5);
    assertNotNull(response);
    assertThat(response.getName(), is(defName));
    assertThat(response.getPayload().getData(), is(payloadDifferentMd5.getData()));
    assertThat(response.getGeneration(), is(generation));
    cache.clear();
    assertThat(cache.size(), is(0));
}
Also used : RawConfig(com.yahoo.vespa.config.RawConfig) Test(org.junit.Test)

Example 4 with RawConfig

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

the class DelayedResponseHandler method checkDelayedResponses.

void checkDelayedResponses() {
    try {
        long start = System.currentTimeMillis();
        if (log.isLoggable(LogLevel.SPAM)) {
            log.log(LogLevel.SPAM, "Running DelayedResponseHandler. There are " + delayedResponses.size() + " delayed responses. First one is " + delayedResponses.responses().peek());
        }
        DelayedResponse response;
        int i = 0;
        while ((response = delayedResponses.responses().poll()) != null) {
            if (log.isLoggable(LogLevel.DEBUG)) {
                log.log(LogLevel.DEBUG, "Returning with response that has return time " + new Date(response.getReturnTime()));
            }
            JRTServerConfigRequest request = response.getRequest();
            ConfigCacheKey cacheKey = new ConfigCacheKey(request.getConfigKey(), request.getConfigKey().getMd5());
            RawConfig config = memoryCache.get(cacheKey);
            if (config != null) {
                rpcServer.returnOkResponse(request, config);
                i++;
            } else {
                log.log(LogLevel.WARNING, "Timed out (timeout " + request.getTimeout() + ") getting config " + request.getConfigKey() + ", will retry");
            }
        }
        if (log.isLoggable(LogLevel.SPAM)) {
            log.log(LogLevel.SPAM, "Finished running DelayedResponseHandler. " + i + " delayed responses sent in " + (System.currentTimeMillis() - start) + " ms");
        }
    } catch (Exception e) {
        // To avoid thread throwing exception and executor never running this again
        log.log(LogLevel.WARNING, "Got exception in DelayedResponseHandler: " + Exceptions.toMessageString(e));
    } catch (Throwable e) {
        com.yahoo.protect.Process.logAndDie("Got error in DelayedResponseHandler, exiting: " + Exceptions.toMessageString(e));
    }
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) RawConfig(com.yahoo.vespa.config.RawConfig) Date(java.util.Date)

Example 5 with RawConfig

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

the class JRTConfigRequestBase method created_from_raw.

@Test
public void created_from_raw() throws IOException {
    RawConfig rawConfig = new RawConfig(new ConfigKey<>(defName, configId, defNamespace), defMd5);
    long serverTimeout = 100000L;
    JRTClientConfigRequest request = createFromRaw(rawConfig, serverTimeout, Trace.createNew(9));
    assertThat(request.getConfigKey().getName(), is(defName));
    JRTServerConfigRequest serverRequest = createReq(request.getRequest());
    assertTrue(serverRequest.validateParameters());
    assertThat(serverRequest.getTimeout(), is(serverTimeout));
    assertThat(serverRequest.getDefContent().asList(), is(rawConfig.getDefContent()));
}
Also used : RawConfig(com.yahoo.vespa.config.RawConfig) Test(org.junit.Test)

Aggregations

RawConfig (com.yahoo.vespa.config.RawConfig)13 Test (org.junit.Test)7 Request (com.yahoo.jrt.Request)2 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)2 FunctionTestConfig (com.yahoo.foo.FunctionTestConfig)1 Slime (com.yahoo.slime.Slime)1 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)1 JRTServerConfigRequest (com.yahoo.vespa.config.protocol.JRTServerConfigRequest)1 File (java.io.File)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Before (org.junit.Before)1