Test with a Feed Simulation

Feed Simulation Introduction

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.

Creating a Feed Simulation File

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.

  1. 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.

  2. 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.

  3. In the Feed Simulation file name field, enter: firstapp-enum. The dialog automatically adds the .sbfs extension.

  4. Click Finish to create the feed simulation and close the wizard.

  5. 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.

  6. In the Stream Selection dialog, open the firstapp project and expand the folders down until you can select the firstapp.sbapp module. Open that down one more level and select the TradesIn stream. Click OK.

  7. 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.

Editing Feed Simulation Values

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. You can instead edit the feed simulation to cycle between enumerated values for both fields in the TradesIn Input Stream.

  1. You change the default behavior, which is to generate random values for each field in the input stream. Instead, you model a set of specific values.

  2. In the Feed Simulation Editor, in the Generation Method section, select the Custom option and click Customize Fields.

  3. In the Customize Fields dialog, define each field as follows:

    1. In the Generation Method column, click and select Enumerated from the dropdown menu.

    2. Select The following values.

    3. Click the Add Row button four times.

    4. Enter these values and weights in the new rows:

      Value Weight
      NKE 1.0
      CMG 2.0
      GMCR 1.0
      FSLR 2.5
    1. In the Generation Method column, select Enumerated again.

    2. Again select the The following values option.

    3. Click the Add Row button six times.

    4. 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.

  4. Click OK to close the dialog.

  5. Press Ctrl+S (Windows) or command+S (Mac) to save your feed simulation.