本文整理汇总了Java中org.apache.storm.testing.MockedSources类的典型用法代码示例。如果您正苦于以下问题:Java MockedSources类的具体用法?Java MockedSources怎么用?Java MockedSources使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockedSources类属于org.apache.storm.testing包,在下文中一共展示了MockedSources类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldSuccessfulSendDatapoint
import org.apache.storm.testing.MockedSources; //导入依赖的package包/类
@Test
public void shouldSuccessfulSendDatapoint() throws Exception {
Datapoint datapoint = new Datapoint("metric", timestamp, Collections.emptyMap(), 123);
MockedSources sources = new MockedSources();
// TODO: rather than use Topic.OTSDB, grab it from the TopologyConfig object (which does
// not exist at this point in the code.
sources.addMockData(Topic.OTSDB+"-spout",
new Values(MAPPER.writeValueAsString(datapoint)));
completeTopologyParam.setMockedSources(sources);
Testing.withTrackedCluster(clusterParam, (cluster) -> {
OpenTSDBTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
});
//verify that request is sent to OpenTSDB server
mockServer.verify(HttpRequest.request(), VerificationTimes.exactly(1));
}
示例2: shouldSendDatapointRequestsOnlyOnce
import org.apache.storm.testing.MockedSources; //导入依赖的package包/类
@Test
public void shouldSendDatapointRequestsOnlyOnce() throws Exception {
Datapoint datapoint = new Datapoint("metric", timestamp, Collections.emptyMap(), 123);
String jsonDatapoint = MAPPER.writeValueAsString(datapoint);
MockedSources sources = new MockedSources();
sources.addMockData(Topic.OTSDB+"-spout",
new Values(jsonDatapoint), new Values(jsonDatapoint));
completeTopologyParam.setMockedSources(sources);
Testing.withTrackedCluster(clusterParam, (cluster) -> {
OpenTSDBTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
});
//verify that request is sent to OpenTSDB server once
mockServer.verify(HttpRequest.request(), VerificationTimes.exactly(1));
}
示例3: verifyEmittedValues
import org.apache.storm.testing.MockedSources; //导入依赖的package包/类
@Test
public void verifyEmittedValues() {
MkClusterParam clusterParam = new MkClusterParam();
clusterParam.setSupervisors(1);
withSimulatedTimeLocalCluster(clusterParam, new TestJob() {
@Override
public void run(ILocalCluster cluster) throws JsonProcessingException {
MockedSources mockedSources = new MockedSources();
mockedSources.addMockData(builder.getSpoutId(), new Values(SWITCH_ID));
Config config = new Config();
config.setDebug(true);
CompleteTopologyParam topologyParam = new CompleteTopologyParam();
topologyParam.setMockedSources(mockedSources);
topologyParam.setStormConf(config);
Map<?, ?> result = completeTopology(cluster, builder.build(), topologyParam);
assertTrue(multiseteq(new Values(new Values(SWITCH_ID)),
readTuples(result, builder.getSpoutId())));
assertTrue(multiseteq(new Values(new Values(SWITCH_ID)),
readTuples(result, builder.getConfirmationBoltId())));
}
});
}
示例4: portStatsTest
import org.apache.storm.testing.MockedSources; //导入依赖的package包/类
@Test
public void portStatsTest() throws Exception {
final String switchId = "00:00:00:00:00:00:00:01";
final List<PortStatsEntry> entries = IntStream.range(1, 53).boxed().map(port -> {
int baseCount = port * 20;
return new PortStatsEntry(port, baseCount, baseCount + 1, baseCount + 2, baseCount + 3,
baseCount + 4, baseCount + 5, baseCount + 6, baseCount + 7,
baseCount + 8, baseCount + 9, baseCount + 10, baseCount + 11);
}).collect(toList());
final List<PortStatsReply> replies = Collections.singletonList(new PortStatsReply(1, entries));
InfoMessage message = new InfoMessage(new PortStatsData(switchId, replies), timestamp, CORRELATION_ID,
Destination.WFM_STATS);
//mock kafka spout
MockedSources sources = new MockedSources();
sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(),
new Values(MAPPER.writeValueAsString(message)));
completeTopologyParam.setMockedSources(sources);
//execute topology
Testing.withTrackedCluster(clusterParam, (cluster) -> {
StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
//verify results
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
ArrayList<FixedTuple> tuples =
(ArrayList<FixedTuple>) result.get(StatsComponentType.PORT_STATS_METRIC_GEN.name());
assertThat(tuples.size(), is(728));
tuples.stream()
.map(this::readFromJson)
.forEach(datapoint -> {
assertThat(datapoint.getTags().get("switchId"), is(switchId.replaceAll(":", "")));
assertThat(datapoint.getTime(), is(timestamp));
assertThat(datapoint.getMetric(), startsWith("pen.switch"));
});
});
}
示例5: meterConfigStatsTest
import org.apache.storm.testing.MockedSources; //导入依赖的package包/类
@Test
public void meterConfigStatsTest() throws Exception {
final String switchId = "00:00:00:00:00:00:00:01";
final List<MeterConfigReply> stats = Collections.singletonList(new MeterConfigReply(2, Arrays.asList(1L, 2L, 3L)));
InfoMessage message = new InfoMessage(new MeterConfigStatsData(switchId, stats), timestamp, CORRELATION_ID,
Destination.WFM_STATS);
//mock kafka spout
MockedSources sources = new MockedSources();
sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(),
new Values(MAPPER.writeValueAsString(message)));
completeTopologyParam.setMockedSources(sources);
//execute topology
Testing.withTrackedCluster(clusterParam, (cluster) -> {
StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
//verify results
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
ArrayList<FixedTuple> tuples =
(ArrayList<FixedTuple>) result.get(StatsComponentType.METER_CFG_STATS_METRIC_GEN.name());
assertThat(tuples.size(), is(3));
tuples.stream()
.map(this::readFromJson)
.forEach(datapoint -> {
assertThat(datapoint.getTags().get("switchid"), is(switchId.replaceAll(":", "")));
assertThat(datapoint.getTime(), is(timestamp));
assertThat(datapoint.getMetric(), is("pen.switch.meters"));
});
});
}
示例6: flowStatsTest
import org.apache.storm.testing.MockedSources; //导入依赖的package包/类
@Test
public void flowStatsTest() throws Exception {
final String switchId = "00:00:00:00:00:00:00:01";
List<FlowStatsEntry> entries = Collections.singletonList(new FlowStatsEntry((short) 1, 0x1FFFFFFFFL, 1500L, 3000L));
final List<FlowStatsReply> stats = Collections.singletonList(new FlowStatsReply(3, entries));
InfoMessage message = new InfoMessage(new FlowStatsData(switchId, stats),
timestamp, CORRELATION_ID, Destination.WFM_STATS);
//mock kafka spout
MockedSources sources = new MockedSources();
sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(),
new Values(MAPPER.writeValueAsString(message)));
completeTopologyParam.setMockedSources(sources);
//execute topology
Testing.withTrackedCluster(clusterParam, (cluster) -> {
StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
//verify results which were sent to Kafka bold
ArrayList<FixedTuple> tuples =
(ArrayList<FixedTuple>) result.get(StatsComponentType.FLOW_STATS_METRIC_GEN.name());
assertThat(tuples.size(), is(4));
tuples.stream()
.map(this::readFromJson)
.forEach(datapoint -> {
assertThat(datapoint.getTags().get("switchid"), is(switchId.replaceAll(":", "")));
assertThat(datapoint.getTime(), is(timestamp));
});
});
}