public RegressionEnvironment sendEventAvro(GenericData.Record theEvent, String typeName) { runtime.getEventService().sendEventAvro(theEvent, typeName); return this; }
private static void sendEvent(EventRepresentationChoice eventRepresentationEnum, RegressionEnvironment env, String eventName, String[] attributes) { if (eventRepresentationEnum.isObjectArrayEvent()) { List<Object> eventObjectArray = new ArrayList<Object>(); for (String attribute : attributes) { String value = attribute.split("=")[1]; eventObjectArray.add(value); } env.sendEventObjectArray(eventObjectArray.toArray(), eventName); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> eventMap = new HashMap<>(); for (String attribute : attributes) { String key = attribute.split("=")[0]; String value = attribute.split("=")[1]; eventMap.put(key, value); } env.sendEventMap(eventMap, eventName); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record record = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured(eventName))); for (String attribute : attributes) { String key = attribute.split("=")[0]; String value = attribute.split("=")[1]; record.put(key, value); } env.eventService().sendEventAvro(record, eventName); } else { fail(); } }
private void makeSendEvent(RegressionEnvironment env, String typeName, EventRepresentationChoice eventRepresentationEnum, Object startTs, Object endTs) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{startTs, endTs}, typeName); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new LinkedHashMap<>(); theEvent.put("startts", startTs); theEvent.put("endts", endTs); env.sendEventMap(theEvent, typeName); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record record = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured(typeName))); record.put("startts", startTs); record.put("endts", endTs); env.eventService().sendEventAvro(record, typeName); } else { throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum); } } }
private static void sendMyInnerSchemaEvent(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, String col1, String col2in1, int col2in2) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{col1, new Object[]{col2in1, col2in2}}, "MyEventSchema"); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> inner = new HashMap<>(); inner.put("in1", col2in1); inner.put("in2", col2in2); Map<String, Object> theEvent = new HashMap<>(); theEvent.put("col1", col1); theEvent.put("col2", inner); env.sendEventMap(theEvent, "MyEventSchema"); } else if (eventRepresentationEnum.isAvroEvent()) { Schema schema = SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("MyEventSchema")); Schema innerSchema = schema.getField("col2").schema(); GenericData.Record innerRecord = new GenericData.Record(innerSchema); innerRecord.put("in1", col2in1); innerRecord.put("in2", col2in2); GenericData.Record record = new GenericData.Record(schema); record.put("col1", col1); record.put("col2", innerRecord); env.eventService().sendEventAvro(record, "MyEventSchema"); } else { fail(); } }
private static void sendMyEvent(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, String in1, int in2) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{in1, in2}, "MyEvent"); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new LinkedHashMap<>(); theEvent.put("in1", in1); theEvent.put("in2", in2); env.sendEventMap(theEvent, "MyEvent"); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("MyEvent"))); theEvent.put("in1", in1); theEvent.put("in2", in2); env.eventService().sendEventAvro(theEvent, "MyEvent"); } else { fail(); } }
private static void sendProduct(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, String product, int size) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{product, size}, "Product"); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new LinkedHashMap<String, Object>(); theEvent.put("product", product); theEvent.put("size", size); env.sendEventMap(theEvent, "Product"); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("Product"))); theEvent.put("product", product); theEvent.put("size", size); env.eventService().sendEventAvro(theEvent, "Product"); } else { fail(); } }
private static void sendOrderEvent(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, String orderId, String productId, double price, int quantity, boolean deletedFlag) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{orderId, productId, price, quantity, deletedFlag}, "OrderEvent"); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new LinkedHashMap<String, Object>(); theEvent.put("orderId", orderId); theEvent.put("productId", productId); theEvent.put("price", price); theEvent.put("quantity", quantity); theEvent.put("deletedFlag", deletedFlag); env.sendEventMap(theEvent, "OrderEvent"); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("OrderEvent"))); theEvent.put("orderId", orderId); theEvent.put("productId", productId); theEvent.put("price", price); theEvent.put("quantity", quantity); theEvent.put("deletedFlag", deletedFlag); env.eventService().sendEventAvro(theEvent, "OrderEvent"); } else { fail(); } }
private static void sendPortfolio(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, String portfolio, String product) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{portfolio, product}, "Portfolio"); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new LinkedHashMap<String, Object>(); theEvent.put("portfolio", portfolio); theEvent.put("product", product); env.sendEventMap(theEvent, "Portfolio"); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("Portfolio"))); theEvent.put("portfolio", portfolio); theEvent.put("product", product); env.eventService().sendEventAvro(theEvent, "Portfolio"); } else { fail(); } } }
private static void makeSendNameValueEvent(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, String typeName, String name, double value) { if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{name, value}, typeName); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new HashMap<>(); theEvent.put("name", name); theEvent.put("value", value); env.sendEventMap(theEvent, typeName); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record record = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured(typeName))); record.put("name", name); record.put("value", value); env.eventService().sendEventAvro(record, typeName); } else { fail(); } } }
private static void tryAssertionWildcard(RegressionEnvironment env, boolean bean, EventRepresentationChoice rep) { RegressionPath path = new RegressionPath(); EPCompiled schemaCompiled; if (bean) { schemaCompiled = env.compile("create schema MySchema as " + MyP0P1Event.class.getName(), options -> options.setBusModifierEventType(ctx -> EventTypeBusModifier.BUS).setAccessModifierEventType(ctx -> NameAccessModifier.PUBLIC)); } else { schemaCompiled = env.compile("create " + rep.getOutputTypeCreateSchemaName() + " schema MySchema (p0 string, p1 string)", options -> options.setBusModifierEventType(ctx -> EventTypeBusModifier.BUS).setAccessModifierEventType(ctx -> NameAccessModifier.PUBLIC)); } path.add(schemaCompiled); env.deploy(schemaCompiled); env.compileDeploy("@name('create') create table TheTable (p0 string, p1 string)", path); env.compileDeploy("insert into TheTable select * from MySchema", path); if (bean) { env.sendEventBean(new MyP0P1Event("a", "b"), "MySchema"); } else if (rep.isMapEvent()) { Map<String, Object> map = new HashMap<String, Object>(); map.put("p0", "a"); map.put("p1", "b"); env.sendEventMap(map, "MySchema"); } else if (rep.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{"a", "b"}, "MySchema"); } else if (rep.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("MySchema"))); theEvent.put("p0", "a"); theEvent.put("p1", "b"); env.eventService().sendEventAvro(theEvent, "MySchema"); } EPAssertionUtil.assertProps(env.iterator("create").next(), "p0,p1".split(","), new Object[]{"a", "b"}); env.undeployAll(); }
env.sendEventMap(new HashMap<String, Object>(), "StartValueEvent"); } else if (eventRepresentationEnum.isAvroEvent()) { env.eventService().sendEventAvro(new GenericData.Record(record("soemthing").fields().endRecord()), "StartValueEvent"); } else { fail(); env.sendEventMap(new HashMap<String, Object>(), "TestInputEvent"); } else if (eventRepresentationEnum.isAvroEvent()) { env.eventService().sendEventAvro(new GenericData.Record(record("soemthing").fields().endRecord()), "TestInputEvent"); } else { fail();
private void tryAssertionCreateSchemaModelAfter(RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum) { String epl = eventRepresentationEnum.getAnnotationText() + " create schema EventTypeOne (hsi int);\n" + eventRepresentationEnum.getAnnotationText() + " create schema EventTypeTwo (event EventTypeOne);\n" + eventRepresentationEnum.getAnnotationText() + " @name('create') create window NamedWindow#unique(event.hsi) as EventTypeTwo;\n" + "on EventTypeOne as ev insert into NamedWindow select ev as event;\n"; env.compileDeployWBusPublicType(epl, new RegressionPath()); if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{10}, "EventTypeOne"); } else if (eventRepresentationEnum.isMapEvent()) { env.sendEventMap(Collections.singletonMap("hsi", 10), "EventTypeOne"); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("EventTypeOne"))); theEvent.put("hsi", 10); env.eventService().sendEventAvro(theEvent, "EventTypeOne"); } else { fail(); } EventBean result = env.statement("create").iterator().next(); EventPropertyGetter getter = result.getEventType().getGetter("event.hsi"); assertEquals(10, getter.get(result)); env.undeployAll(); } }
public void run(RegressionEnvironment env) { String epl = eventRepresentationEnum.getAnnotationText() + " @name('schema') create schema SchemaOne(col1 int, col2 int);\n"; epl += eventRepresentationEnum.getAnnotationText() + " @name('create') create window SchemaWindow#lastevent as (s1 SchemaOne);\n"; epl += "insert into SchemaWindow (s1) select sone from SchemaOne as sone;\n"; env.compileDeployWBusPublicType(epl, new RegressionPath()).addListener("create"); assertTrue(eventRepresentationEnum.matchesClass(env.statement("schema").getEventType().getUnderlyingType())); assertTrue(eventRepresentationEnum.matchesClass(env.statement("create").getEventType().getUnderlyingType())); if (eventRepresentationEnum.isObjectArrayEvent()) { env.sendEventObjectArray(new Object[]{10, 11}, "SchemaOne"); } else if (eventRepresentationEnum.isMapEvent()) { Map<String, Object> theEvent = new LinkedHashMap<>(); theEvent.put("col1", 10); theEvent.put("col2", 11); env.sendEventMap(theEvent, "SchemaOne"); } else if (eventRepresentationEnum.isAvroEvent()) { GenericData.Record theEvent = new GenericData.Record(SupportAvroUtil.getAvroSchema(env.runtime().getEventTypeService().getEventTypePreconfigured("SchemaOne"))); theEvent.put("col1", 10); theEvent.put("col2", 11); env.eventService().sendEventAvro(theEvent, "SchemaOne"); } else { fail(); } EPAssertionUtil.assertProps(env.listener("create").assertOneGetNewAndReset(), "s1.col1,s1.col2".split(","), new Object[]{10, 11}); env.undeployAll(); } }