14 Testing 1-2-3

Oracle Event Processing provides different ways to test your application depending on what and how you want to test.

This chapter includes the following sections:

14.1 Load Generator and the csvgen Adapter

The load generator utility simulates a data feed so that you can test your application without connecting to a real-world data feed. To test your application with the load generator, you must use the csvgen adapter in your application because the csvgen adapter is specifically coded to decipher the data packets generated by the load generator. Once you have tested your application with the csvgen adapter, you can replaced it with the appropriate input adapter for your application as described in Adapters.

The load generator reads an ASCII file that contains the sample data feed information and sends each line of data in order to a port. The csvgen adapter listens for data at the same port.

A load generator properties file indicates the name of the data file, the port where the server listens, the server host, and the packet type. You can also set the data rate and how long it takes for the load generator to ramp up to a specified final rate.

The following steps present an overview of how to configure and run the load generator utility. Detailed information for each step follows.

  1. Create a properties file that contains the configuration properties for particular run of the load generator. Oracle Event Processing provides a default property file you can use if the default property values are adequate. See Create the Properties File.

  2. Create a file that contains the actual data feed values. See Create the Data Feed File.

  3. Configure the csvgen adapter so that it correctly reads the data feed generated by the load generator. See Configure the csvgen Adapter in Your Application.

  4. Run the load generator and specify the properties file you created in step 1 to begin the simulated data feed. For example, if the name of your properties file is c:\loadgen\myDataFeed.prop, execute the following command:

    prompt> runloadgen.cmd c:\loadgen\myDataFeed.prop
    

    If you redeploy your application, you must also restart the load generator.

  5. To stop and load generator, go to directory where you have load generator running and type ctrl-c.

14.1.1 Create the Properties File

Oracle Event Processing provides a default properties file called csvgen.prop in the /Oracle/Middleware/my_oep/utils/load-generator directory. The format of the file is simple: each property-value pair is on its own line.

The following example shows the default csvgen.prop file; Oracle recommends you use this file as a template for your own property file:

# name of file containing your test data
  test.csvDataFile=test.csv
# port the server will listen on for client connection
  test.port=9001
# server host (localhost if not specified)
# test.host=
# do not change the packetType
  test.packetType=CSV

Table 14-1 Load Generator Properties

Property Description Data Type Required?

test.csvDataFile

Specifies the file that contains the data feed values.

String

Yes

test.port

The port number to which the load generator sends the data feed.

Each input adapter must be associated with its own test.port.

Integer

Yes

test.secs

Total duration of the load generator run, in seconds.

The default value is 30.

Integer

No

test.rate

Final data rate, in messages per second.

The default value is 1.

Integer

No

test.startRate

Initial data rate, in messages per second.

The default value is 1.

Integer

No

test.rampUpSecs

Number of seconds to ramp up from test.startRate to test.rate.

The default value is 0.

Integer

No

14.1.2 Create the Data Feed File

A load generator data feed file contains the sample data feed values that correspond to the event type registered for your Oracle Event Processing application.

The following example show an EmployeeEvent and a load generator data feed file corresponding to this event type.

<wlevs:event-type-repository>
        <wlevs:event-type type-name="EmployeeEvent">
            <wlevs:properties>
                <wlevs:property name="name" type="char" />
                <wlevs:property name="age" type="int" />
                <wlevs:property name="birthplace" type="char" length="512" />
        </wlevs:properties>
    </wlevs:event-type>
...
</wlevs:event-type-repository>
 Lucy,23,Madagascar
 Nick,44,Canada
 Amanda,12,Malaysia
 Juliet,43,Spain
 Horatio,80,Argentina

A load generator data feed file follows a simple format:

  • Put each data feed item is on its own line.

  • Separate the fields of a data feed item with commas.

  • Do not include commas in a string field.

  • Do not include extraneous spaces before or after the commas, unless the space is literally part of the field value.

  • Include only string and numerical data in a data feed file such as integer, long, double, and float.

  • Keep within the maximum string length of 256 characters or specify a long string length. To specify a longer string, set the length attribute of the char property in your event-type for the birthplace property.

Note:

The load generator does not fully comply with the CSV specification at http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm

For more information about CSV adapter constraints, see Design Constraints.

14.1.3 Configure the csvgen Adapter in Your Application

When using the load generator utility, you must use the csvgen adapter in your application because this Oracle Event Processing-provided adapter is specifically coded to read the data packets generated by the load generator.

You register the csvgen adapter using the wlevs:adapter element in the EPN assembly file of your application, as with all adapters. Set the provide attribute to csvgen to specify that the provider is the csvgen adapter, rather than your own adapter. Additionally, you must specify the following child tags:

  • wlevs:instance-property element with name attribute port and value attribute configured_port, where configured_port corresponds to the value of the test.port property in the load generator property file. See Create the Properties File.

  • wlevs:instance-property element with name attribute eventTypeName and value attribute event_type_name, where event_type_name corresponds to the name of the event type that represents an item from the load-generated feed.

  • wlevs:instance-property element with name attribute eventPropertyNames and value attribute ordered_list_of_properties, where ordered_list_of_properties lists the names of the properties in the order that the load generator sends them, and consequently the csvgen adapter receives them.

Before showing an example of how to configure the adapter, first assume that your application registers an event type called PersonType in the EPN assembly file using the wlevs:metada element shown below:

<wlevs:event-type-repository>
        <wlevs:event-type type-name="PersonType">
            <wlevs:properties>
               <wlevs:property name="name" type="char"/>
               <<wlevs:property name="age" type="int"/>
               <<wlevs:property name="birthplace" type="char"/>
            </wlevs:properties>
        </wlevs:event-type>
</wlevs:event-type-repository>

This event type corresponds to the data feed file shown in Create the Data Feed File.

To configure the csvgen adapter that receives this data, use the following wlevs:adapter element:

<wlevs:adapter id="csvgenAdapter" provider="csvgen">
   <wlevs:instance-property name="port" value="9001"/>
   <wlevs:instance-property name="eventTypeName" value="PersonType"/>
   <wlevs:instance-property name="eventPropertyNames" value="name,age,birthplace"/>
</wlevs:adapter>

Note how the bold values in the adapter configuration example correspond to the PersonType event type registration.

If you use the wlevs:class element to specify your own JavaBean when registering the event type, then the eventPropertyNames value corresponds to the JavaBean properties. For example, if your JavaBean has a getName method, then one of the properties of your JavaBean is name.

For more information on event types, see Events and Event Types.

14.2 Event Inspector Service

Use the Event Inspector service to test and debug Oracle CQL queries during development. With the Event Inspector service you can view (trace) the events that flow out of any EPN stage and inject events into any EPN stage. The Event Inspector service uses a common HTTP pub-sub channel and server to trace and inject events.

Note:

Do not use the Event Inspector service on a production Oracle Event Processing server. Use this service during development only.

A trace event must have its binding attribute set to outbound, and an injected event must have its binding attribute set to inbound. Using an Event Inspector client, you can inject:

  • A single, simple event by type, such as the StockTick event. The specific event property types that you can use depends on the client.

  • A single event directly to the HTTP pub-sub channel as a JSON-formatted character string. You can use any event property that JSON can represent.

  • Multiple events using a file that contains one or more JSON-formatted character strings. You can use any event property that JSON can represent. The Event Inspector service client parses the file and injects all of its JSON strings to the HTTP pub-sub channel.

You can use the GSON Java library to help you convert Java objects to JSON format when creating your input file. For more information, see:

The Event Inspector service supports Oracle Event Processing Visualizer. See Oracle Fusion Middleware Using Visualizer for Oracle Event Processing.

14.2.1 Event Types

The Event Inspector service supports all Oracle Event Processing event types: JavaBean class, Map, and tuple. The Event Inspector service converts events to the JavaScript Object Notation (JSON) format before publishing to the trace channel. You must inject events in JSON format.

Note:

Byte arrays are not supported as property types in event types used with the event inspector.

JSON-formatted events must conform to the structure. Table 14-1 lists the required attributes.

{
    "event-type": "myEventType",
    "operation": "insert",
    "binding": "outbound",
    "value":{
        "firstname": "Jane",
        "lastname": "Doe",
        "phone": {
            "code": 12345,
            "number": "office"
        },
    }
}

Table 14-2 Event Inspector JSON Event Required Attributes

Attribute Description

event-type

The name of the Oracle Event Processing event as you defined it in the application assembly file's event-type-repository.

operation

Specify the type of event:

  • insert: insert event.

  • delete: delete event

  • update: update event

  • heartbeat: heartbeat event

binding

One of:

  • inbound: injected event.

  • outbound: trace event.

value

One or more JSON-formatted event properties as defined by the event-type.

14.2.2 HTTP Publish-Subscribe Channel and Server

The Event Inspector service uses a dynamic HTTP publish-subscribe (HTTP pub-sub) channel with the following name that is defined in the server config.xml file:

/SERVERNAME/APPLICATIONNAME/STAGENAME/DIRECTION

SERVERNAME: The name of the Oracle Event Processing server where the EPN stage runs.

APPLICATIONNAME: the name of the Oracle Event Processing application.

STAGENAME: the name of the EPN stage.

DIRECTION: one of either:

  • input: Event injection.

  • output: Event tracing.

For example:

/server-1/myapp/MyInputAdapter/input

The Event Inspector service uses an HTTP pub-sub server. This can be any of:

  • Local: You configure the server file with an event-inspector element and configure its pubsub-server-name child element with the name of the local pubsub server that is running on this machine.

  • Remote: You configure the server file with an event-inspector element and configure its pubsub-server-url child element with a URL to an HTTP pub-sub server that is running on a remote machine.

  • Default: if there is only one HTTP pub-sub server defined in the server file, and you do not specify a local or remote HTTP pub-sub server, the Event Inspector service uses the local HTTP pub-sub server by default.

The Event Inspector service uses the same HTTP pub-sub channel and server for tracing and injecting events.

14.2.3 Configure a Local or Remote Server

You can configure the Event Inspector service with a local or remote HTTP pub-sub server. You configure the Event Inspector HTTP pub-sub server in a component configuration file. When there is only one HTTP pub-sub server defined in the server, and you do not specify a local or remote HTTP pub-sub server, the Event Inspector service uses the local HTTP pub-sub server by default.

Configure for a Local HTTP Publish-Subscribe Server

For any component configuration file that has a component that you want to test, add the event-inspector name element as follows.

<event-inspector>
    <name>myEventInspectorConfig</name>
    <pubsub-server-name>myPubSub</pubsub-server-name>
</event-inspector>

The pubsub-server-name value myPubSub is the value of the http-pubsub element name child element as defined in the local Oracle Event Processing server file as the following example shows.

<http-pubsub>
  <name>myPubSub</name>
  <path>/pubsub</path>
  <pub-sub-bean>
    <server-config>
      <supported-transport>
        <types>
          <element>long-polling</element>
        </types>
      </supported-transport>
      <publish-without-connect-allowed>true</publish-without-connect-allowed>
    </server-config>
    <channels>
        ...
    </channels>
  </pub-sub-bean>
</http-pubsub>

Configure for a Remote HTTP Publish-Subscribe Server

For any component configuration file that has a component that you want to test, add the event-inspector name element as follows.

<event-inspector>
  <name>myEventInspectorTraceConfig</name>
  <pubsub-server-url>http://HOST:PORT/PATH</pubsub-server-url>
</event-inspector>

HOST: The host name or IP address of the remote Oracle Event Processing server.

PORT: The remote Oracle Event Processing server netio port as defined in the remote Oracle Event Processing server file. Default: 9002.

PATH: The value of the http-pubsub element path child element as defined in the remote Oracle Event Processing server file.

Given the http-pubsub configuration that the example shows, a valid pubsub-server-url would be as follows:

http://remotehost:9002/pubsub

The pubsub-server-name value myPubSub is the value of the http-pubsub element name child element as defined in the local Oracle Event Processing server file as the following example shows.

<http-pubsub>
  <name>myPubSub</name>
  <path>/pubsub</path>
  <pub-sub-bean>
    <server-config>
      <supported-transport>
        <types>
          <element>long-polling</element>
        </types>
      </supported-transport>
      <publish-without-connect-allowed>true</publish-without-connect-allowed>
    </server-config>
    <channels>
          ...
    </channels>
  </pub-sub-bean>
</http-pubsub>

14.2.4 Inject Events

After you configure the Event Inspector service HTTP pub-sub server, you can use Event Inspector clients to inject events. To configure event injection, you can use the Oracle Event Processing Visualizer, or you can edit a component configuration file in your application to specify injection settings that are in place when the application is deployed or redeployed.

Configure event injection in Oracle Event Processing Visualizer with settings that can be discarded when the application is redeployed. See Oracle Fusion Middleware Using Visualizer for Oracle Event Processing.

For event injection configuration settings that are in place when the application is deployed or redeployed, configure injection by editing component configuration settings for the stage to which you want to inject.

For example, the component configuration excerpt shown in the example illustrates how you might configure a processor for event injection. The inject-parameters element's active child element specifies that injection is on, while the channel-name element specifies the HTTP pub-sub channel from which injected elements should be sent.

<processor>
    <name>FindCrossRates</name>
    <inject-parameters>
        <active>true</active>
        <channel-name>/NonClusteredServer/fx/FindCrossRates/output</channel-name>
    </inject-parameters>
    <rules>
        <!-- Query rules omitted. -->
    </rules>
</processor>

For reference information about the elements, see Oracle Fusion Middleware Schema Reference for Oracle Event Processing.

14.2.5 Trace Events

After you configure the Event Inspector service HTTP pub-sub server, you can use Event Inspector clients to trace events flowing out of any stage of your EPN. To trace events, you can either use the Oracle Event Processing Visualizer to configure tracing or you can edit a component configuration file in your application to specify trace settings that are in place when the application is deployed or redeployed.

Configure event tracing in Oracle Event Processing Visualizer with settings that can be discarded when the application is redeployed. See Oracle Fusion Middleware Using Visualizer for Oracle Event Processing.

For event tracing configuration settings that are in place when the application is deployed or redeployed, configure tracing by editing component configuration settings for the stage from which you want to trace.

For example, the component configuration excerpt shown in the example illustrates how you might configure a processor for event tracing. The trace-parameters element's active child element specifies that tracing is on, while the channel-name element specifies the HTTP pub-sub channel to which traced elements should be sent.

<processor>
    <name>FindCrossRates</name>
    <trace-parameters>
        <active>true</active>
        <channel-name>/NonClusteredServer/fx/FindCrossRates/output</channel-name>
    </trace-parameters>
    <rules>
        <!-- Query rules omitted. -->
    </rules>
</processor>

For reference information about the elements, see Oracle Fusion Middleware Schema Reference for Oracle Event Processing.

14.2.6 Event Inspector API

You can use the Event Inspector API to inject and trace events. The Oracle Event Processing API provides the EventInspectorMBean interface that you can implement to control the event tracing and injection behavior. Only the administrator and monitor administrator roles can invoke the startInject, stopInject, startTrace, and stopTrace methods. See Oracle Fusion Middleware Java API Reference for Oracle Event Processing for information about the EventInspectorMBean interface and its methods.

Once you implement the EventInspectorMBean interface, you can call its methods from your application to inject and trace events as follows.

Inject Events

  1. Get an instance of com.bea.wlevs.eventinspector.management.EventInspectorMBean from the server through JMX.

  2. Call the EventInspectorMBean.startInject method to start event injection on the stage specified in the server config.xml file configuration for an HTTP publish-Subscribe channel as explained in HTTP Publish-Subscribe Channel and Server.

  3. Publish events to the specified HTTP publish-subscribe channel.

  4. Use the EventInspectorMBean.isInjecting method to verify that event injection has started on the stage.

  5. Call the EventInspectorMBean.stopInject method to stop event injection.

Trace Events

  1. Get an instance of com.bea.wlevs.eventinspector.management.EventInspectorMBean from the server through JMX.

  2. Call the EventInspectorMBean.startTrace method to start event tracing on the stage specified in the server config.xml file configuration for an HTTP publish-subscribe channel as explained in HTTP Publish-Subscribe Channel and Server.

  3. Use the EventInspectorMBean.isTracing method to verify that event tracing has started on the HTTP Publish-Subscribe channel.

  4. Call the EventInspectorMBean.stopTrace method to stop event tracing.

14.3 EPN Shell

The EPN shell provides shell commands for testing Oracle Event Processing applications. See EPN Command Interface for information about how to perform EPN operations programmatically.

The EPN shell extends the Apache Felix Gogo shell, which provides a standard shell command prompt for OSGi frameworks. See the Apache Felix Gogo documentation at: http://felix.apache.org/documentation/subprojects/apache-felix-gogo.html.

To start the server in the EPN shell, go to /Oracle/Middleware/my_oep/ user_projects/domains/<my_domain>/<server> and start the Oracle Event Processing server in the EPN shell as follows:

UNIX:

./startwlevs.sh -shell
...
g!

Windows:

startwlevs.cmd -shell
...
g!

When the EPN shell starts, you see the g! prompt. Type help to display a list of all of the commands. The commands specific to EPN, are prefixed by epn:, for example, epn:channel.

g! help

To display help about a particular command, type help <command>. For example, to see help about the begin command, type the following:

g! help begin
begin - Begins new session for invoking EPN commands
   scope: epn
   parameters:
      CommandSession

Note:

Some of the Apache Felix Gogo commands have a CommandSession argument, which is an internal shell argument that does not execute with the Apache Felix Gogo commands. When you do a help listing for some of the EPN shell commands, the CommandSession parameter is listed by the help, but does not work.

14.3.1 Oracle CQL Queries

By default, an EPN session has an implicit Oracle CQL processor that is connected to an event sink that prints all outputs to the shell console. To test Oracle CQL queries, create an input channel, define the queries, and send events as follows:

g! begin
g! channel MyChannel [msg=String]
MyChannel
g! query "select * from MyChannel"
q0
g! send MyChannel [msg='Hi']
11:14:26 618 -> insert event: {msg=Hi}
q! end

Use the begin command to start an EPN session and the end command to end an EPN session. Ending a session destroys all EPN components that were created during that session. A session is not multithread aware.

The channel command creates MyChannel with an event-type that has the msg property of type String. You can also specify a Java class name for the event-type.

The query command registers the "select * query from MyChannel“ in the implicit Oracle CQL processor for this session. You can remove the query from the processor with the remove command.

The send command dispatches an insert event to MyChannel. If the session has a single channel only, then the name of the channel is optional. For example, the following two commands are equivalent: “send MyChannel [msg='Hi']" and “send [msg='Hi']".

The syntax “[msg='Hi']" creates a map that contains a single key-value pair, with a key of “msg" and a value of “Hi". This matches the event-type created in the first line with channel MyChannel [msg=String].

You can use the update and delete commands to send an update event and a delete event to a relation-based channel. The insert command is equivalent to the send command. Also, you can check the current registered statements in a session with the statement command and find out the channels you have created in a session with the channels command. The eventtypes commands enables you to display the structure of all event-types in the server.

For more information about Oracle CQL processor queries, see Oracle CQL Processors.

14.3.2 Management Commands

Management commands enable you to list the deployed Oracle Event Processing applications, list libraries, install an application, send events to an existing application, subscribe to channel events, list all public stages, retrieve an OSGi service and call standard Java methods, perform JMX operations, and shut down the server.

List all deployed Oracle Event Processing applications in the running server:

g! listapps
com.bea.wlevs.dataservices

List all Oracle Event Processing libraries. This commen lists all of the bundles that are unzipped in the modules directory to run the EPN shell.

g! llistlibs
org.apache.felix.bundlerepository
org.apache.felix.gogo.runtime
com.oracle.cep.shell
org.apache.felix.gogo.command
org.apache.felix.gogo.shell

Install a new application. The following example deploys and immediately starts the application.

g! deployapp file:///Users./oepapps/hwlloworld.jar

Undeploy an application:

g! deployapp file:///Users./oepapps/hwlloworld.jar
g! undeployapp file:///Users./oepapps/hwlloworld.jar

Send events to an existing Oracle Event Processing application by specifying the full name of the channel when you use the send, insert, update, and delete commands. This example sends an event to the helloworldInputChannel in the helloworld application. For this to work, you must advertise the channel so the EPN shell can find it. To advertise the channel, set the advertise attribute to true in the assembly file first.

Assembly file setting:

<wlevs:channel id="helloworldInputChannel" event-type="HelloWorldEvent" advertise="true" >

EPN shell commands:

g! event1=createevent HelloWorldEvent
g! $event1 message "Hi Shell"
g! send helloworld:helloworldInputChannel $event1

Subscribe to a channel. The events subscribed to are sent either to the shell console or to a file when you specify a file name. Make sure the channel is advertised by setting the advertise attribute to true in the assembly file. The following command subscribes to all output from the helloworld application and send the output to the shell console:

g! subscribe helloworld:helloworldOutputChannel

List all public (advertised) stages in the application.

g!introspect helloworld
Application 'helloworld' provides the following OCEP services:
Event Channel 'helloworldOutputChannel' for Event Type 'HelloWorldEvent'

Retrieve the CQLProcessorMBean for the helloworld Oracle CQL processor and invoke the getAllQueries operation.

g! proc = mbean helloworld:helloworldProcessor CQLProcessor
g! $proc allQueries
helloworldRule
select * from helloworldInputChannel

You can use the retrieved mbean with the mbean command to test and manipulate JMX operations.

Stop the server.

g! stop

14.3.3 Regression Testing

You can automate application testing by running the shell headless and using scripts. For example, you can execute the following script named send-event.oep by specifying the gosh.args system property in the startwlevs command.

begin
channel -a [a=Long]
query "select * from ch0"
send 0 [a=1]
send 1 [a=2]
end

Note:

In a script, use double quotes to enclose a String tuple value with the send command. For example, send [msg="Enter a value."]. Single quotes do not work in a script.

To execute the send-event.oep script when you start the server, edit the last line of the startwlevs command as follows:

"$JAVA_HOME/bin/java" -Dgosh.args=send-event.oep $JVM_ARGS $DEBUG_ARGS -Dwlevs.home="$USER_INSTALL_DIR" -Dbea.home="$BEA_HOME"  -jar "${USER_INSTALL_DIR}/bin/wlevs.jar" $ARGS

One approach is to have a test driver script that invokes other scripts and directs their output, as follows:

source send-event.oep | tac test-output/log/send-event.out
source test-delete.oep | tac test-output/log/test-delete.out

14.3.4 EPN Variable

You can set the time stamp format or turn time stamps off for an EPN session.

OUT_TIME: FORMATTED | PLAIN | OFF

To turn off the time stamp on output events, enter the following:

g! OUT_TIME=OFF

To indicate formatted time stamping.

h! OUT_TIME=FORMATTED

14.3.5 EPN Commands

The EPN commands are shown and described in the following list.

epn:begin: Begins a new session for invoking EPN commands.

epn:channel: Performs different actions based on the parameters:

  • Create a channel with a map-based event type.

  • Create a named relation channel with update keys and a Java class event type.

  • Create a named channel with a map-based event type.

  • Create a named channel with a Java class event type.

  • Create a channel with a Java class event type.

  • Create a named relation channel with update keys and a map-based event type.

epn:channels: Lists all channels within the EPN scope.

epn:createevent: Creates an event of the provided event type.

epn:end: Ends the EPN session.

epn:eventtypes: Lists all event types

epn:heartbeat: Sends a heartbeat to channel that is time stamped by an application.

epn:query: Registers an Oracle CQL query.

epn:remove: Removes all statements that are registered within the EPN scope.

epn:send: Sends an insert event to a named channel. Same as the sendinsert command.

epn:senddelete: Deletes a named event in a named channel.

epn:sendinsert: Sends an insert event to a named channel. Same as the send command.

epn:sendupdate: Updates an OSGi bundle with the bundle at the provided URL.

epn:statements: Lists all registered Oracle CQL statements within the EPN scope.

epn:subscribe: Subscribe to an event channel and output events to a file.

epn:unsubscribe: Unsubscribe from an event channel.

epn:view: Register an Oracle CQL view.

14.3.6 Management Commands

The management commands are shown and described in the following list.

mngt:deployapp: Deploys an application with optional parameters.

mngt:deployrepapp: Deploys an application from the respository.

mngt:introspect: Introspects an application for its public interfaces.

mngt:listapps: Lists all deployed applications.

mngt:listlibs: Lists all deployed libraries.

mngt:mbean: Retrieves the MBean stage from the local MBean server

mngt:shutdown: Shuts the server down.

mngt:undeployapp: Undeploys the specified application.

14.4 EPN Command Interface

The EpnCommand interface is a Java API on top of the Oracle Event Processing EPN CQL programming model. You can use the EpnCommand interface in a Java application to manipulate EPN components. You can programmatically start an EPN session and execute EPN commands similar to using the command-line EPN shell described in EPN Shell.

Use beginSession() to start an EPN session and endSession() to end an EPN session. Ending a session destroys all EPN components that were created during that session. A session is not multithread aware and must be synchronized in your application code.

To use EPN commands in an Oracle Event Processing application, first retrieve the EpnCommand OSGi service, which registers the service as an OSGi service factory. Once you retrieve the OSGi service, you can create test cases similar to JUnit test cases for testing EPN components and Oracle CQL statements. Only the commands exposed in the EpnCommand class as methods can be use for JUnit-like test cases.

You can also use the EpnCommand interface to create an Oracle Event Processing application through programming.

14.4.1 Session Variables

You can set session variables to indicate the time stamp format to use for output events. The time stamping can be FORMATTED, PLAIN, or OFF.

14.4.2 Methods

void beginSession(): Begins a new session for invoking commands. Only a single session can be active at one time. The following list shows the EpnCommand methods and parameters. Refer the EpnCommand Javadoc for more information.

endSession(): Ends the current session. Only a single session can be active at one time.

void getEventChannels(): Returns all channels created in the current session.

EventChannel[] getEventChannel(String channelName): Returns the named event channel.

EventChannel getEventChannel(String channelName): Retrieves the named event channel.

Create different types of channels based on the parameters.

  • EventChannel createChannel(String channelName, Class<?> clazz): Create a new system time stamped channel with a Java class event type.

  • EventChannel createChannel(boolean relation, String applicationTimestampProp, boolean totalOrder, List<String> keys, String channelName, Class<?> class): Create a new channel with a Java class event type.

  • EventChannel createChannel(boolean relation, String applicationTimestampProp, boolean totalOrder, List<String> keys, String channelName, Class<?> class, EventBuilder.Factory factory): Create a new channel with a Java class event type.

  • EventChannel createChannel(String channelName, Map<String, String> metadata): Create a new system timestamped channel with a metadata-based event type.

  • EventChannel createChannel(boolean relation, String applicationTimestampProp, boolean totalOrder, List<String> keys, String channelName, Map<String, String> metadata): Create a new channel with a metadata-based event type.

  • EventChannel createChannel(boolean relation, String applicationTimestampProp, boolean totalOrder, List<String> keys, String channelName, Map<String, String> metadata, EventBuilder.Factory factory): Create a new channel with a metadata-based event type.

Processor[] getProcessors(): Returns all Oracle CQL processors created in the current session.

Processor createProcessor(): Creates an Oracle CQL processor in the current session.

StreamSource link(StreamSource fromStage, StreamSink toStage): Connects a stage to stage.

void unlink(StreamSource source, StreamSink sink): Disconnects the source from the sink.

Statement createView(Processor processor, String id, String StatementValue): Creates an Oracle CQL view.

Statement createQuery(Processor processor, String id, String statementValue): Creates an Oracle CQL query.

Object createEvent(String eventTypeName): Creates an event based on the event type name. The event is created only when it is available in the Event Type repository.

MapEventObject createMapEvent(EventChannel channel, Map<String, Object> event): Create a map event for a metadata-based channel.

void sendInsert(String channelName, Object event): Send an insert event to the channel.

void sendUpdate(String channelName, Object event): Send an update event to the channel.

void sendDelete(String channelName, Object event): Send a delete event to the channel.

void sendHeartbeat(Long timestamp, String channelName): Send a heartbeat to the channel.

14.4.3 Example

The following example shows a basic JUnit test case.

//Get the OSGI service
ServiceReference ref = ctx.getServiceReference(EpnCommand.class.getName());
commandSession = (EpnCommand) ctx.getService(ref);

//Begin a session
commandSession.begin();

//Create an Oracle CQL processor 
Processor p1 = commandSession.createProcessor("p1");

//Create two stream channels from the MyEvent Java class.
EventChannel ch1 = commandSession.createChannel(false, "c1", MyEvent.class);  EventChannel ch2 = commandSession.createChannel(false, "c2", MyEvent.class);

//Create a listener to retrieve events that equal event e1
//The MyEventListener class implements the StreamSink or RelationSink interface
MyEventListener listener = new MyEventListener();

//Connect channel ch1 and processor p1
commandSession.link((StreamSource) ch1, (StreamSink) p1);
 
//Connect channel p1 and processor ch2
commandSession.link((StreamSource) p1, (StreamSink) ch2);
 
//Connect channel ch2 and processor listener
commandSession.link((StreamSource) ch2, (StreamSink) listener);

//Create the query in processor p1
commandSession.createQuery(p1, "q1", "select * from c1");

//Create event e1 and assign two properties, a and 1.
Object e1 = new MyEvent("a", 1);

//Send insert event e1 to channel ch1
ch1.sendInsertEvent(e1);

//Test whether event e1 equals the event retrieved by the listener
assertEquals(e1, listener.getEvent());

//End the session        
commandSession.end();