From bd9868fcaabef2e8cec89e23acce32d30c2f65ab Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Thu, 12 Jul 2018 16:24:52 +0200 Subject: [PATCH] [536794] Adds tests for the use of the flattener predicate Change-Id: I0e1c0b5c7883c75c16ce63566ecbcf7596d36467 Signed-off-by: Zoltan Ujhelyi --- .../META-INF/MANIFEST.MF | 4 + .../plugin.xml | 34 ++++++ .../cps/tests/FlattenerPredicateTest.xtend | 110 ++++++++++++++++++ .../FlattenerPredicateQueries.vql | 40 +++++++ 4 files changed, 188 insertions(+) create mode 100644 query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend create mode 100644 query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/queries/flattenerpredicate/FlattenerPredicateQueries.vql diff --git a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/META-INF/MANIFEST.MF b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/META-INF/MANIFEST.MF index ed3af647ce..228dc2cc74 100644 --- a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/META-INF/MANIFEST.MF +++ b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/META-INF/MANIFEST.MF @@ -5,6 +5,10 @@ Bundle-SymbolicName: org.eclipse.viatra.query.runtime.cps.tests;singleton:=true Bundle-Version: 2.0.1.qualifier Bundle-Vendor: The Eclipse VIATRA Project Export-Package: org.eclipse.viatra.query.runtime.cps.tests.queries, + org.eclipse.viatra.query.runtime.cps.tests.queries.api, + org.eclipse.viatra.query.runtime.cps.tests.queries.api.util, + org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate, + org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util, org.eclipse.viatra.query.runtime.cps.tests.queries.resolveordering, org.eclipse.viatra.query.runtime.cps.tests.queries.resolveordering.util, org.eclipse.viatra.query.runtime.cps.tests.queries.util diff --git a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/plugin.xml b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/plugin.xml index e5af3bb7b6..cdbcdcb265 100644 --- a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/plugin.xml +++ b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/plugin.xml @@ -64,6 +64,12 @@ + + + + + + @@ -96,6 +102,17 @@ + + + + + + + + + + + @@ -183,6 +200,23 @@ + + + + + + + + + + + + + + + + + diff --git a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend new file mode 100644 index 0000000000..a5b941591b --- /dev/null +++ b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/FlattenerPredicateTest.xtend @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2014-2018 Zoltan Ujhelyi, IncQuery Labs Ltd. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Zoltan Ujhelyi - initial API and implementation + *******************************************************************************/ +package org.eclipse.viatra.query.runtime.cps.tests + +import java.util.Collection +import org.eclipse.emf.ecore.resource.ResourceSet +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl +import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine +import org.eclipse.viatra.query.runtime.api.IPatternMatch +import org.eclipse.viatra.query.runtime.api.IQuerySpecification +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions +import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher +import org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util.Called_dQuerySpecification +import org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util.Called_iQuerySpecification +import org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util.Called_sQuerySpecification +import org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util.Callee_dQuerySpecification +import org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util.Callee_iQuerySpecification +import org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate.util.Callee_sQuerySpecification +import org.eclipse.viatra.query.runtime.emf.EMFScope +import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory +import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchGenericBackendFactory +import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints +import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory +import org.eclipse.viatra.query.testing.core.XmiModelUtil +import org.eclipse.viatra.query.testing.core.XmiModelUtil.XmiModelUtilRunningOptionEnum +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import org.junit.runners.Parameterized.Parameter +import org.junit.runners.Parameterized.Parameters + +@RunWith(Parameterized) +class FlattenerPredicateTest { + static val queryBackends = #[ReteBackendFactory.INSTANCE, LocalSearchEMFBackendFactory.INSTANCE, LocalSearchGenericBackendFactory.INSTANCE] + static val DEFAULT_OPTION = ViatraQueryEngineOptions.^default + static val SEARCH_OPTION = ViatraQueryEngineOptions.defineOptions.withDefaultBackend(LocalSearchEMFBackendFactory.INSTANCE).build + static val INCREMENTAL_OPTION = ViatraQueryEngineOptions.defineOptions.withDefaultBackend(ReteBackendFactory.INSTANCE).build + @Parameters() + def static Collection testData() { + #[ + // Default engine options, default modifiers, should be flattened + #[DEFAULT_OPTION, Callee_dQuerySpecification.instance, Called_dQuerySpecification.instance, true], + // Default engine options, incremental modifiers, should not be flattened + #[DEFAULT_OPTION, Callee_iQuerySpecification.instance, Called_iQuerySpecification.instance, false], + // Default engine options, search modifiers, should be flattened + #[DEFAULT_OPTION, Callee_sQuerySpecification.instance, Called_sQuerySpecification.instance, true], + // Search engine, default modifiers, should be flattened + #[SEARCH_OPTION, Callee_dQuerySpecification.instance, Called_dQuerySpecification.instance, true], + // Search engine, incremental modifiers, should not be flattened + #[SEARCH_OPTION, Callee_iQuerySpecification.instance, Called_iQuerySpecification.instance, false], + // Search engine, search modifiers, should be flattened + #[SEARCH_OPTION, Callee_sQuerySpecification.instance, Called_sQuerySpecification.instance, true], + // Incremental engine, default modifiers, should be flattened + #[INCREMENTAL_OPTION, Callee_dQuerySpecification.instance, Called_dQuerySpecification.instance, true], + // Incremental engine, incremental modifiers, should not be flattened + #[INCREMENTAL_OPTION, Callee_iQuerySpecification.instance, Called_iQuerySpecification.instance, false], + // Incremental engine, search modifiers, should be flattened + #[INCREMENTAL_OPTION, Callee_sQuerySpecification.instance, Called_sQuerySpecification.instance, true] + ] + } + + @Parameter(0) + public ViatraQueryEngineOptions engineOptions + @Parameter(1) + public IQuerySpecification> queryToFlatten + @Parameter(2) + public IQuerySpecification> queryFlattened + @Parameter(3) + public boolean shouldCallBeFlattened + + + public String modelPath = "org.eclipse.viatra.query.runtime.cps.tests/models/instances/demo.cyberphysicalsystem" + ResourceSet rs + + @Before + def void prepareTest() { + val modelUri = XmiModelUtil::resolvePlatformURI(XmiModelUtilRunningOptionEnum.BOTH, modelPath) + rs = new ResourceSetImpl + rs.getResource(modelUri, true) + } + + @Test + def void flattenedPatternCallTest() { + val engine = AdvancedViatraQueryEngine.createUnmanagedEngine(new EMFScope(rs), engineOptions) + try { + engine.getMatcher(queryToFlatten, LocalSearchHints.^default.build) + Assert.assertTrue(shouldCallBeFlattened.xor(engine.hasResultProviderForQuery(queryFlattened))) + } finally { + engine.dispose + } + } + + def boolean hasResultProviderForQuery(AdvancedViatraQueryEngine engine, IQuerySpecification query) { + queryBackends.exists[backend | + engine.getQueryBackend(backend).peekExistingResultProvider(query.internalQueryRepresentation) !== null + ] + } + + +} diff --git a/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/queries/flattenerpredicate/FlattenerPredicateQueries.vql b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/queries/flattenerpredicate/FlattenerPredicateQueries.vql new file mode 100644 index 0000000000..12268d04ae --- /dev/null +++ b/query/tests/org.eclipse.viatra.query.runtime.cps.tests/src/org/eclipse/viatra/query/runtime/cps/tests/queries/flattenerpredicate/FlattenerPredicateQueries.vql @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010-2018, Zoltan Ujhelyi, IncQuery Labs Ltd. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Zoltan Ujhelyi - initial API and implementation + *******************************************************************************/ +package org.eclipse.viatra.query.runtime.cps.tests.queries.flattenerpredicate + +import "http://org.eclipse.viatra/model/cps" + +pattern called_d(a : HostInstance) { + HostInstance(a); +} + +pattern callee_d(a1 : HostInstance, a2 : HostInstance) { + find called_d(a1); + HostInstance.communicateWith(a1, a2); +} + +search pattern called_s(a : HostInstance) { + HostInstance(a); +} + +pattern callee_s(a1 : HostInstance, a2 : HostInstance) { + find called_s(a1); + HostInstance.communicateWith(a1, a2); +} + +incremental pattern called_i(a : HostInstance) { + HostInstance(a); +} + +pattern callee_i(a1 : HostInstance, a2 : HostInstance) { + find called_i(a1); + HostInstance.communicateWith(a1, a2); +} \ No newline at end of file