Search in sources :

Example 1 with CacheStatistics

use of org.teiid.adminapi.CacheStatistics in project teiid by teiid.

the class TestODataIntegration method testSkipToken.

@Test
public void testSkipToken() throws Exception {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("vw");
        mmd.addSourceMetadata("ddl", "create view x (a string primary key, b integer) " + "as select 'xyz', 123 union all select 'abc', 456;");
        mmd.setModelType(Model.Type.VIRTUAL);
        teiid.deployVDB("northwind", mmd);
        Properties props = new Properties();
        props.setProperty("batch-size", "1");
        localClient = getClient(teiid.getDriver(), "northwind", props);
        ContentResponse response = http.GET(baseURL + "/northwind/vw/x?$format=json");
        assertEquals(200, response.getStatus());
        String starts = "{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"abc\",\"b\":456}]," + "\"@odata.nextLink\":\"" + baseURL + "/northwind/vw/x?$format=json&$skiptoken=";
        String ends = ",1\"}";
        assertTrue(response.getContentAsString(), response.getContentAsString().startsWith(starts));
        assertTrue(response.getContentAsString(), response.getContentAsString().endsWith(ends));
        JsonNode node = getJSONNode(response);
        String nextLink = node.get("@odata.nextLink").asText();
        response = http.GET(nextLink);
        assertEquals(200, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
        CacheStatistics stats = teiid.getAdmin().getCacheStats(Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.name()).iterator().next();
        // first query misses, second hits
        assertEquals(50, stats.getHitRatio(), 0);
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : CacheStatistics(org.teiid.adminapi.CacheStatistics) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Properties (java.util.Properties)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1 Test (org.junit.Test)1 CacheStatistics (org.teiid.adminapi.CacheStatistics)1 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)1