Search in sources :

Example 1 with QueryResult

use of org.opendaylight.mdsal.binding.api.query.QueryResult in project mdsal by opendaylight.

the class QueryPerformanceTest method queryLessThanAlarm.

@Test
public void queryLessThanAlarm() throws InterruptedException, ExecutionException {
    final String needle = "alias" + (SYSTEM_COUNT - 1);
    final Stopwatch sw = Stopwatch.createStarted();
    final QueryExpression<System> query = factory.querySubtree(InstanceIdentifier.create(Foo.class)).extractChild(System.class).matching().leaf(System::getAlias).valueEquals(needle).build();
    LOG.info("Query built in {}", sw);
    sw.reset().start();
    final FluentFuture<QueryResult<@NonNull System>> future;
    try (ReadTransaction rtx = getDataBroker().newReadOnlyTransaction()) {
        assertThat(rtx, instanceOf(QueryReadTransaction.class));
        future = ((QueryReadTransaction) rtx).execute(LogicalDatastoreType.CONFIGURATION, query);
    }
    final QueryResult<@NonNull System> result = future.get();
    LOG.info("Query executed {} in {}", future, sw);
    assertTrue(result.stream().findAny().isPresent());
    LOG.info("Query result in {}", sw);
}
Also used : QueryResult(org.opendaylight.mdsal.binding.api.query.QueryResult) QueryReadTransaction(org.opendaylight.mdsal.binding.api.QueryReadTransaction) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) QueryReadTransaction(org.opendaylight.mdsal.binding.api.QueryReadTransaction) NonNull(org.eclipse.jdt.annotation.NonNull) Stopwatch(com.google.common.base.Stopwatch) System(org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System) AbstractDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest) Test(org.junit.Test)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Test (org.junit.Test)1 QueryReadTransaction (org.opendaylight.mdsal.binding.api.QueryReadTransaction)1 ReadTransaction (org.opendaylight.mdsal.binding.api.ReadTransaction)1 QueryResult (org.opendaylight.mdsal.binding.api.query.QueryResult)1 AbstractDataBrokerTest (org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest)1 System (org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System)1