Java Code Examples for backtype.storm.testing.FeederSpout

The following are top voted examples for showing how to use backtype.storm.testing.FeederSpout. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: big-data-system   File: SingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
  FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
  FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

  TopologyBuilder builder = new TopologyBuilder();
  builder.setSpout("gender", genderSpout);
  builder.setSpout("age", ageSpout);
  builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id"))
      .fieldsGrouping("age", new Fields("id"));

  Config conf = new Config();
  conf.setDebug(true);

  LocalCluster cluster = new LocalCluster();
  cluster.submitTopology("join-example", conf, builder.createTopology());

  for (int i = 0; i < 10; i++) {
    String gender;
    if (i % 2 == 0) {
      gender = "male";
    }
    else {
      gender = "female";
    }
    genderSpout.feed(new Values(i, gender));
  }

  for (int i = 9; i >= 0; i--) {
    ageSpout.feed(new Values(i, i + 20));
  }

  Utils.sleep(2000);
  cluster.shutdown();
}
 
Example 2
Project: jstrom   File: SingleJoinTest.java   Source Code and License 5 votes vote down vote up
@Test
public void test_single_join() {
    try {
        FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
        FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("gender", genderSpout);
        builder.setSpout("age", ageSpout);
        builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id"))
                .fieldsGrouping("age", new Fields("id"));

        Config conf = new Config();
        conf.setDebug(true);

        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("join-example", conf, builder.createTopology());

        for (int i = 0; i < 10; i++) {
            String gender;
            if (i % 2 == 0) {
                gender = "male";
            } else {
                gender = "female";
            }
            genderSpout.feed(new Values(i, gender));
        }

        for (int i = 9; i >= 0; i--) {
            ageSpout.feed(new Values(i, i + 20));
        }

        JStormUtils.sleepMs(60 * 1000);
        cluster.shutdown();
    } catch (Exception e) {
        Assert.fail("Failed to run SingleJoinExample");
    }
}
 
Example 3
Project: cdh-storm   File: SingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
  FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
  FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

  TopologyBuilder builder = new TopologyBuilder();
  builder.setSpout("gender", genderSpout);
  builder.setSpout("age", ageSpout);
  builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id"))
      .fieldsGrouping("age", new Fields("id"));

  Config conf = new Config();
  conf.setDebug(true);

  LocalCluster cluster = new LocalCluster();
  cluster.submitTopology("join-example", conf, builder.createTopology());

  for (int i = 0; i < 10; i++) {
    String gender;
    if (i % 2 == 0) {
      gender = "male";
    }
    else {
      gender = "female";
    }
    genderSpout.feed(new Values(i, gender));
  }

  for (int i = 9; i >= 0; i--) {
    ageSpout.feed(new Values(i, i + 20));
  }

  Utils.sleep(2000);
  cluster.shutdown();
}
 
Example 4
Project: storm-query-operators   File: SingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
  FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
  FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

  TopologyBuilder builder = new TopologyBuilder();
  builder.setSpout("gender", genderSpout);
  builder.setSpout("age", ageSpout);
  builder.setBolt("join", new SimpleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id"))
      .fieldsGrouping("age", new Fields("id"));
  builder.setBolt("printer", new PrinterBolt()).shuffleGrouping("join");

  Config conf = new Config();
  conf.setDebug(true);

  LocalCluster cluster = new LocalCluster();
  cluster.submitTopology("join-example", conf, builder.createTopology());

  for (int i = 0; i < 10; i++) {
    String gender;
    if (i % 2 == 0) {
      gender = "male";
    }
    else {
      gender = "female";
    }
    genderSpout.feed(new Values(i, gender));
  }

  for (int i = 9; i >= 0; i--) {
    ageSpout.feed(new Values(i, i + 20));
  }

  Utils.sleep(2000);
  cluster.shutdown();
}
 
Example 5
Project: storm-query-operators   File: ExtendedSingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
// Define the spouts
   FeederSpout observationSpout = new FeederSpout(new Fields("obsId", "observedProperty", "value", "uom", "timestamp", "sensorId"));
   FeederSpout sensorSpout = new FeederSpout(new Fields("sensorId", "lat", "lon"));

   // Define the topology
   TopologyBuilder builder = new TopologyBuilder();
   builder.setSpout("observation", observationSpout);
   builder.setSpout("sensor", sensorSpout);
   builder.setBolt("join", new ExtendedSingleJoinBolt(new Fields("obsId", "observedProperty", "value", "uom", "timestamp", "lat", "lon")))
   	.fieldsGrouping("sensor", new Fields("sensorId")).fieldsGrouping("observation", new Fields("sensorId"));
   builder.setBolt("printer", new AckerPrinterBolt()).shuffleGrouping("join");
   
   Config conf = new Config();
   //conf.setDebug(true);

   LocalCluster cluster = new LocalCluster();
   cluster.submitTopology("extended-join-example", conf, builder.createTopology());

   try {
    // Simulate data - Feed the spouts
    for (int i = 9; i >= 0; i--) {
    	sensorSpout.feed(new Values(i, 40.4055389 - i, 10.8399527 - i));
		Thread.sleep(500);
    }
    
    for (int i = 0; i < 50; i++) {
    	observationSpout.feed(new Values(i, "temperature", Math.random()%10, "degrees Celsius", new Date(System.currentTimeMillis()), i%10));
    	Thread.sleep(100);
    }
 	} catch (InterruptedException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
    

   Utils.sleep(10000);
   cluster.shutdown();
 }
 
Example 6
Project: incubator-storm   File: SingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
  FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
  FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

  TopologyBuilder builder = new TopologyBuilder();
  builder.setSpout("gender", genderSpout);
  builder.setSpout("age", ageSpout);
  builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id"))
      .fieldsGrouping("age", new Fields("id"));

  Config conf = new Config();
  conf.setDebug(true);

  LocalCluster cluster = new LocalCluster();
  cluster.submitTopology("join-example", conf, builder.createTopology());

  for (int i = 0; i < 10; i++) {
    String gender;
    if (i % 2 == 0) {
      gender = "male";
    }
    else {
      gender = "female";
    }
    genderSpout.feed(new Values(i, gender));
  }

  for (int i = 9; i >= 0; i--) {
    ageSpout.feed(new Values(i, i + 20));
  }

  Utils.sleep(2000);
  cluster.shutdown();
}
 
Example 7
Project: sentweet   File: SingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
    FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
    FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("gender", genderSpout);
    builder.setSpout("age", ageSpout);
    builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age")))
            .fieldsGrouping("gender", new Fields("id"))
            .fieldsGrouping("age", new Fields("id"));
    
    Config conf = new Config();
    conf.setDebug(true);
    
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("join-example", conf, builder.createTopology());
    
    for(int i=0; i<10; i++) {
        String gender;
        if(i % 2 == 0) {
            gender = "male";
        } else {
            gender = "female";
        }
        genderSpout.feed(new Values(i, gender));
    }
    
    for(int i=9; i>=0; i--) {            
        ageSpout.feed(new Values(i, i+20));
    }
    
    Utils.sleep(2000);
    cluster.shutdown();
}
 
Example 8
Project: CadalWorkspace   File: SingleJoinExample.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
    FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
    FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("gender", genderSpout);
    builder.setSpout("age", ageSpout);
    builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age")))
            .fieldsGrouping("gender", new Fields("id"))
            .fieldsGrouping("age", new Fields("id"));
    
    Config conf = new Config();
    conf.setDebug(true);
    
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("join-example", conf, builder.createTopology());
    
    for(int i=0; i<10; i++) {
        String gender;
        if(i % 2 == 0) {
            gender = "male";
        } else {
            gender = "female";
        }
        genderSpout.feed(new Values(i, gender));
    }
    
    for(int i=9; i>=0; i--) {            
        ageSpout.feed(new Values(i, i+20));
    }
    
    Utils.sleep(2000);
    cluster.shutdown();
}
 
Example 9
Project: jstorm-0.9.6.3-   File: SingleJoinTest.java   Source Code and License 4 votes vote down vote up
@Test
public void test_single_join() {
	try {
		FeederSpout genderSpout = new FeederSpout(
				new Fields("id", "gender"));
		FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

		TopologyBuilder builder = new TopologyBuilder();
		builder.setSpout("gender", genderSpout);
		builder.setSpout("age", ageSpout);
		builder.setBolt("join",
				new SingleJoinBolt(new Fields("gender", "age")))
				.fieldsGrouping("gender", new Fields("id"))
				.fieldsGrouping("age", new Fields("id"));

		Config conf = new Config();
		conf.setDebug(true);

		LocalCluster cluster = new LocalCluster();
		cluster.submitTopology("join-example", conf,
				builder.createTopology());

		for (int i = 0; i < 10; i++) {
			String gender;
			if (i % 2 == 0) {
				gender = "male";
			} else {
				gender = "female";
			}
			genderSpout.feed(new Values(i, gender));
		}

		for (int i = 9; i >= 0; i--) {
			ageSpout.feed(new Values(i, i + 20));
		}

		JStormUtils.sleepMs(60 * 1000);
		cluster.shutdown();
	} catch (Exception e) {
		Assert.fail("Failed to run SingleJoinExample");
	}
}
 
Example 10
Project: learn_jstorm   File: SingleJoinTest.java   Source Code and License 4 votes vote down vote up
@Test
public void test_single_join() {
	try {
		FeederSpout genderSpout = new FeederSpout(
				new Fields("id", "gender"));
		FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

		TopologyBuilder builder = new TopologyBuilder();
		builder.setSpout("gender", genderSpout);
		builder.setSpout("age", ageSpout);
		builder.setBolt("join",
				new SingleJoinBolt(new Fields("gender", "age")))
				.fieldsGrouping("gender", new Fields("id"))
				.fieldsGrouping("age", new Fields("id"));

		Config conf = new Config();
		conf.setDebug(true);

		LocalCluster cluster = new LocalCluster();
		cluster.submitTopology("join-example", conf,
				builder.createTopology());

		for (int i = 0; i < 10; i++) {
			String gender;
			if (i % 2 == 0) {
				gender = "male";
			} else {
				gender = "female";
			}
			genderSpout.feed(new Values(i, gender));
		}

		for (int i = 9; i >= 0; i--) {
			ageSpout.feed(new Values(i, i + 20));
		}

		JStormUtils.sleepMs(60 * 1000);
		cluster.shutdown();
	} catch (Exception e) {
		Assert.fail("Failed to run SingleJoinExample");
	}
}
 
Example 11
Project: jstorm   File: SingleJoinTest.java   Source Code and License 4 votes vote down vote up
@Test
public void test_single_join() {
	receiveCounter.set(0);
	try {
		FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
		FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));

		TopologyBuilder builder = new TopologyBuilder();
		builder.setSpout("gender", genderSpout);
		builder.setSpout("age", ageSpout);
		builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age")))
				.fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));

		Config conf = new Config();
		conf.setDebug(true);

		LocalCluster cluster = new LocalCluster();
		cluster.submitTopology("join-example", conf, builder.createTopology());

		for (int i = 0; i < 10; i++) {
			String gender;
			if (i % 2 == 0) {
				gender = "male";
			} else {
				gender = "female";
			}
			genderSpout.feed(new Values(i, gender));
		}

		for (int i = 9; i >= 0; i--) {
			ageSpout.feed(new Values(i, i + 20));
		}

		JStormUtils.sleepMs(60 * 1000);

		assertNotSame(0, receiveCounter.get());

		cluster.shutdown();
	} catch (Exception e) {
		Assert.fail("Failed to run SingleJoinExample");
	}
}