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 the firstapp project.
Select the src/main/resources folder, right-click and from the context menu, select New>Feed Simulation. This opens a dialog much like the following, with the resources folder pre-selected.
In the Feed Simulation file name field, enter: firstapp-enum. The dialog automatically adds the .sbfs extension.
Click Finish 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 Copy from Stream/Named Schema 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 the firstapp.sbapp module. Open that down one more level and select the TradesIn stream. Click OK.
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 Customize Fields.
In the Generation Method column, click and select Enumerated from the drop-down menu.
Click the Add Row button four times.
In the Generation Method column, select Enumerated again.
Again select the The following values option.
Click the Add Row button six times.
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.
Press Ctrl+S (Windows) or command+S (Mac) to save your feed simulation.