Contents
To test a fragment without manually enqueing tuples, you can let your fragment connect to a live incoming feed of the data stream it is designed to process. However, most of the time, connecting to live data would be expensive, or inappropriate, or or even dangerous. For example, you would never connect a fragment under development to a live feed of actual customer transaction data.
StreamBase instead provides its feed simulation mechanism. This lets you send a stream of generated or recorded data to your fragment's input streams. The feed simulation feature has many features that offer maximum flexibility. Learn more about feed simulations on these pages.
Feed simulations are stored as files with the .sbfs
extension. Place these files in the src/main/resources
folder of your Studio project.
For this tutorial, we will create and customize a feed simulation that cycles between
enumerated values for each field in the firstapp
module's TradesIn
Input Stream.
-
There are several ways to start a new feed simulation file, but the most convenient is to open the project in the Project Explorer view and navigate to its
src/main/resources
folder. Do that now for thefirstapp
project. -
Select the
src/main/resources
folder, right-click and from the context menu, select > . This opens a dialog much like the following, with theresources
folder pre-selected. -
In the Feed Simulation file name field, enter:
firstapp-enum
. The dialog automatically adds the.sbfs
extension. -
Click
to create the new feed simulation and close the wizard. -
Your new file opens in the Feed Simulation Editor.
In the Simulation Streams area, you must identify a stream for the feed simulation to feed and define its schema. The easiest way to do that is to click to borrow the stream's schema from the module.
-
In the Stream Selection dialog, open the
firstapp
project and expand folders down until you can select thefirstapp.sbapp
module. Open that down one more level and select theTradesIn
stream. Click . -
This places the TradesIn stream into the Simulation Streams area. Open the arrow symbol on the left side of the stream's name to see the schema of the imported stream.
The default behavior of newly created feed simulation files is to generate random
values for all input stream fields, using the appropriate data type for each field.
We will instead edit the feed simulation to cycle between enumerated values for both
fields in the TradesIn
Input Stream.
-
You will change the default behavior, which is to generate random values for each field in the input stream. Instead, you will model a set of specific values.
-
In the Feed Simulation Editor, in the Generation Method section, select the Custom option and click .
-
In the Customize Fields dialog, define each field as follows:
- symbol
-
-
In the Generation Method column, click and select from the drop-down menu.
-
Select The following values.
-
Click the
button four times. -
Enter these values and weights in the new rows:
Value Weight NKE 1.0 CMG 2.0 GMCR 1.0 FSLR 2.5
-
- quantity
-
-
In the Generation Method column, select again.
-
Again select the The following values option.
-
Click the
button six times. -
Enter these values and weights:
Value Weight 30000 0.1 10000 0.1 100 0.2 200 0.2 400 0.2 1000 0.2
-
The weights determine the relative frequency of values generated. By default, all weights are 1.0, meaning all values are equally likely to appear. A fractional weight of 0.2 means that the specified value is to appear 20% of the time.
-
Click
to close the dialog. -
Press Ctrl+S (Windows) or command+S (Mac) to save your feed simulation.