/* * ************************************************************************************* * Copyright (C) 2008 EsperTech, Inc. All rights reserved. * * http://esper.codehaus.org * * http://www.espertech.com * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the GPL license * * a copy of which has been included with this distribution in the license.txt file. * * ************************************************************************************* */ package com.espertech.esper.regression.epl; import com.espertech.esper.client.*; import com.espertech.esper.client.scopetest.SupportUpdateListener; import com.espertech.esper.support.bean.SupportBean; import com.espertech.esper.support.bean.SupportBean_S0; import com.espertech.esper.support.client.SupportConfigFactory; import junit.framework.TestCase; public class TestNamedWindowSubqFilteredCorrel extends TestCase { private EPServiceProvider epService; public void setUp() { Configuration config = SupportConfigFactory.getConfiguration(); epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); epService.getEPAdministrator().getConfiguration().addEventType("SupportBean", SupportBean.class); epService.getEPAdministrator().getConfiguration().addEventType("ABean", SupportBean_S0.class); } public void testNoShare() { runAssertion(false, false, false); } public void testNoShareCreate() { runAssertion(false, false, true); } public void testShare() { runAssertion(true, false, false); } public void testShareCreate() { runAssertion(true, false, true); } public void testDisableShare() { runAssertion(true, true, false); } public void testDisableShareCreate() { runAssertion(true, true, true); } private void runAssertion(boolean enableIndexShareCreate, boolean disableIndexShareConsumer, boolean createExplicitIndex) { SupportUpdateListener listener = new SupportUpdateListener(); epService.getEPAdministrator().getConfiguration().addEventType("SupportBean", SupportBean.class); epService.getEPAdministrator().getConfiguration().addEventType("S0", SupportBean_S0.class); String createEpl = "create window SupportWindow.win:keepall() as select * from SupportBean"; if (enableIndexShareCreate) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } epService.getEPAdministrator().createEPL(createEpl); epService.getEPAdministrator().createEPL("insert into SupportWindow select * from SupportBean"); EPStatement indexStmt = null; if (createExplicitIndex) { indexStmt = epService.getEPAdministrator().createEPL("create index MyIndex on SupportWindow(theString)"); } epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); epService.getEPRuntime().sendEvent(new SupportBean("E2", -2)); String consumeEpl = "select (select intPrimitive from SupportWindow(intPrimitive<0) sw where s0.p00=sw.theString) as val from S0 s0"; if (disableIndexShareConsumer) { consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl; } EPStatement consumeStmt = epService.getEPAdministrator().createEPL(consumeEpl); consumeStmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E1")); assertEquals(null, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "E2")); assertEquals(-2, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean("E3", -3)); epService.getEPRuntime().sendEvent(new SupportBean("E4", 4)); epService.getEPRuntime().sendEvent(new SupportBean_S0(-3, "E3")); assertEquals(-3, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "E4")); assertEquals(null, listener.assertOneGetNewAndReset().get("val")); consumeStmt.stop(); if (indexStmt != null) { indexStmt.stop(); } consumeStmt.destroy(); if (indexStmt != null) { indexStmt.destroy(); } } }