use of org.testng.annotations.Test in project storm by apache.
the class RankableObjectWithFieldsTest method shouldCreateRankableObjectFromTuple.
@Test
public void shouldCreateRankableObjectFromTuple() {
// given
Tuple tuple = mock(Tuple.class);
List<Object> tupleValues = Lists.newArrayList(ANY_OBJECT, ANY_COUNT, ANY_FIELD);
when(tuple.getValues()).thenReturn(tupleValues);
// when
RankableObjectWithFields r = RankableObjectWithFields.from(tuple);
// then
assertThat(r.getObject()).isEqualTo(ANY_OBJECT);
assertThat(r.getCount()).isEqualTo(ANY_COUNT);
List<Object> fields = new ArrayList<Object>();
fields.add(ANY_FIELD);
assertThat(r.getFields()).isEqualTo(fields);
}
use of org.testng.annotations.Test in project storm by apache.
the class RankingsTest method updatingWithNewRankablesShouldBeThreadSafe.
@Test
public void updatingWithNewRankablesShouldBeThreadSafe() throws InterruptedException {
// given
final List<Rankable> entries = ImmutableList.of(A, B, C, D);
final Rankings rankings = new Rankings(entries.size());
// We are capturing exceptions thrown in Blitzer's child threads into this data structure so that we can properly
// pass/fail this test. The reason is that Blitzer doesn't report exceptions, which is a known bug in Blitzer
// (JMOCK-263). See https://github.com/jmock-developers/jmock-library/issues/22 for more information.
final List<Exception> exceptions = Lists.newArrayList();
Blitzer blitzer = new Blitzer(1000);
// when
blitzer.blitz(new Runnable() {
public void run() {
for (Rankable r : entries) {
try {
rankings.updateWith(r);
} catch (RuntimeException e) {
synchronized (exceptions) {
exceptions.add(e);
}
}
}
}
});
blitzer.shutdown();
//
if (!exceptions.isEmpty()) {
for (Exception e : exceptions) {
System.err.println(Throwables.getStackTraceAsString(e));
}
}
assertThat(exceptions).isEmpty();
}
use of org.testng.annotations.Test in project storm by apache.
the class DemoTest method testExclamationTopology.
@Test
public void testExclamationTopology() throws Exception {
topo = new TopoWrap(cluster, topologyName, ExclamationTopology.getStormTopology());
topo.submitSuccessfully();
final int minExclaim2Emits = 500;
final int minSpountEmits = 10000;
for (int i = 0; i < 10; ++i) {
TopologyInfo topologyInfo = topo.getInfo();
log.info(topologyInfo.toString());
long wordSpoutEmittedCount = topo.getAllTimeEmittedCount(ExclamationTopology.WORD);
long exclaim1EmittedCount = topo.getAllTimeEmittedCount(ExclamationTopology.EXCLAIM_1);
long exclaim2EmittedCount = topo.getAllTimeEmittedCount(ExclamationTopology.EXCLAIM_2);
log.info("wordSpoutEmittedCount for spout 'word' = " + wordSpoutEmittedCount);
log.info("exclaim1EmittedCount = " + exclaim1EmittedCount);
log.info("exclaim2EmittedCount = " + exclaim2EmittedCount);
if (exclaim2EmittedCount > minExclaim2Emits || wordSpoutEmittedCount > minSpountEmits) {
break;
}
TimeUtil.sleepSec(6);
}
List<TopoWrap.ExecutorURL> boltUrls = topo.getLogUrls(ExclamationTopology.WORD);
log.info(boltUrls.toString());
final String actualOutput = topo.getLogs(ExclamationTopology.EXCLAIM_2);
for (String oneExpectedOutput : exclaim2Oputput) {
Assert.assertTrue(actualOutput.contains(oneExpectedOutput), "Couldn't find " + oneExpectedOutput + " in urls");
}
}
use of org.testng.annotations.Test in project storm by apache.
the class SlidingWindowTest method testTimeWindow.
@Test(dataProvider = "generateTimeWindows")
public void testTimeWindow(int windowSec, int slideSec) throws Exception {
final SlidingTimeCorrectness testable = new SlidingTimeCorrectness(windowSec, slideSec);
final String topologyName = this.getClass().getSimpleName() + "w" + windowSec + "s" + slideSec;
if (windowSec <= 0 || slideSec <= 0) {
try {
testable.newTopology();
Assert.fail("Expected IllegalArgumentException was not thrown.");
} catch (IllegalArgumentException ignore) {
return;
}
}
topo = new TopoWrap(cluster, topologyName, testable.newTopology());
runAndVerifyTime(windowSec, slideSec, testable, topo);
}
use of org.testng.annotations.Test in project storm by apache.
the class TumblingWindowTest method testTumbleCount.
@Test(dataProvider = "generateWindows")
public void testTumbleCount(int tumbleSize) throws Exception {
final TumblingWindowCorrectness testable = new TumblingWindowCorrectness(tumbleSize);
final String topologyName = this.getClass().getSimpleName() + "t" + tumbleSize;
if (tumbleSize <= 0) {
try {
testable.newTopology();
Assert.fail("Expected IllegalArgumentException was not thrown.");
} catch (IllegalArgumentException ignore) {
return;
}
}
topo = new TopoWrap(cluster, topologyName, testable.newTopology());
SlidingWindowTest.runAndVerifyCount(tumbleSize, tumbleSize, testable, topo);
}
Aggregations