/* * ************************************************************************************* * 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.Configuration; import com.espertech.esper.client.EPServiceProvider; import com.espertech.esper.client.EPServiceProviderManager; import com.espertech.esper.client.EPStatement; import com.espertech.esper.client.scopetest.EPAssertionUtil; 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.bean.SupportBean_S1; import com.espertech.esper.support.client.SupportConfigFactory; import junit.framework.TestCase; public class TestNamedWindowSubqCorrelJoin extends TestCase { private EPServiceProvider epService; private SupportUpdateListener listener; public void setUp() { Configuration config = SupportConfigFactory.getConfiguration(); epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); epService.getEPAdministrator().getConfiguration().addEventType("SupportBean", SupportBean.class); epService.getEPAdministrator().getConfiguration().addEventType("S0Bean", SupportBean_S0.class); epService.getEPAdministrator().getConfiguration().addEventType("S1Bean", SupportBean_S1.class); listener = new SupportUpdateListener(); } protected void tearDown() throws Exception { listener = null; } public void testNoShare() { runAssertion(false); } public void testShare() { runAssertion(true); } private void runAssertion(boolean enableIndexShareCreate) { String createEpl = "create window MyWindow.std:unique(theString) as select * from SupportBean"; if (enableIndexShareCreate) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } epService.getEPAdministrator().createEPL(createEpl); epService.getEPAdministrator().createEPL("insert into MyWindow select * from SupportBean"); String consumeEpl = "select (select intPrimitive from MyWindow where theString = s1.p10) as val from S0Bean.std:lastevent() as s0, S1Bean.std:lastevent() as s1"; EPStatement consumeStmt = epService.getEPAdministrator().createEPL(consumeEpl); consumeStmt.addListener(listener); String[] fields = "val".split(","); epService.getEPRuntime().sendEvent(new SupportBean("E1", 10)); epService.getEPRuntime().sendEvent(new SupportBean("E2", 20)); epService.getEPRuntime().sendEvent(new SupportBean("E3", 30)); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "E1")); assertFalse(listener.isInvoked()); epService.getEPRuntime().sendEvent(new SupportBean_S1(1, "E2")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{20}); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "E3")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{20}); epService.getEPRuntime().sendEvent(new SupportBean_S1(1, "E1")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{10}); epService.getEPRuntime().sendEvent(new SupportBean_S1(1, "E3")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{30}); consumeStmt.stop(); consumeStmt.destroy(); } }