Package com.streamreduce.storm

Examples of com.streamreduce.storm.MockOutputCollector


     * @throws Exception if anything goes wrong
     */
    @Test
    @Ignore("This test never finishes.")
    public void testConnectionSpout() throws Exception {
        MockOutputCollector outputCollector = new MockOutputCollector();
        ConnectionSpout spout = new ConnectionSpout();

        spout.open(null, null, new SpoutOutputCollector(outputCollector));

        long connectionCount = spout.getQueue().size();
        boolean complete = false;
        int calls = 0;

        while (!complete) {
            boolean wasSleeping = spout.isQuiet();

            spout.nextTuple();

            // If the spout was sleeping and isn't after nextTuple or vice
            // versa, that means there wasn't an emission from the spout.
            if (!wasSleeping && !spout.isQuiet()) {
                calls++;

                if (calls / connectionCount == 2 && calls % connectionCount == 0) {
                    // Stop testing after cycling through two queues
                    complete = true;
                }
            }

            Assert.assertEquals(calls, outputCollector.getEmittedSpoutValues().size());
        }
    }
View Full Code Here


     *
     * @throws Exception if anything goes wrong
     */
    @Test
    public void testEventSpoutWithDate() throws Exception {
        MockOutputCollector outputCollector = new MockOutputCollector();
        final Date lastEventDate = new Date(System.currentTimeMillis() - 10000); // 10s ago
        EventSpout spout = new EventSpout(lastEventDate);

        spout.open(null, null, new SpoutOutputCollector(outputCollector));

View Full Code Here

    @Test
    @Ignore("Ignored until EventService and Event model objects can be properly factored/replaced in analytics tests.")
    public void testEventSpout() throws Exception {
//        EventService eventService = applicationManager.getEventService();
//        List<Event> allEvents = new ArrayList<Event>();
        MockOutputCollector outputCollector = new MockOutputCollector();
        EventSpout spout = new EventSpout();
        List<BasicDBObject> allRawEvents = new ArrayList<>();

        spout.open(null, null, new SpoutOutputCollector(outputCollector));

        // Add all events
        allRawEvents.addAll(spout.getQueue());

        // Filter out any events in the raw events after the last event date in the
        // events returned from the service.  (This is to work around a potential
        // situation where an event(s) is fired in between getting events via the
        // EventService and via the EventSpout.
        final Date lastEventDate = new Date(allRawEvents.get(allRawEvents.size() - 1).getLong("timestamp"));

//        allEvents.addAll(Collections2.filter(eventService.getEventsForAccount(null), new Predicate<Event>() {
//            @Override
//            public boolean apply(Event event) {
//                Date eventDate = new Date(event.getTimestamp());
//
//                return !eventDate.after(lastEventDate);
//            }
//        }));
//
//        // Make sure the events in the queue and the events in the DB collection are the same
//        Assert.assertEquals(allEvents.size(), allRawEvents.size());

        // Exhaust the queue
        while (!spout.isQuiet()) {
            spout.nextTuple();
            if (Math.random() < 0.3) {
                BasicDBObject last = (BasicDBObject) outputCollector.getLastEmmitedValue().get(0);
                Assert.assertNotNull(last);
                spout.fail(last.get("_id"));
            }
        }

        // Wait until we re-poll for new events
        while(spout.isQuiet()) {
            Thread.sleep(10000);

            spout.nextTuple();
        }

        // Get expected total of events
        int totalEventsEmitted = allRawEvents.size() + spout.getQueue().size();

        // Exhaust the queue
        while (!spout.isQuiet()) {
            spout.nextTuple();
        }

        // Make sure events processed count is as expected
        Assert.assertEquals(totalEventsEmitted, outputCollector.getEmittedSpoutValues().size());

        // Validate the events were sent to the proper stream
        for (Map.Entry<String, List<Values>> entry : outputCollector.getEmittedSpoutValuesMap().entrySet()) {
            String streamId = entry.getKey();
            List<Values> events = entry.getValue();

            for (Values values : events) {
                BasicDBObject event = (BasicDBObject)values.get(0);
View Full Code Here

     */
    protected Map<String, Float> processEvents(List<Map<String, Object>> events) {
        Map<String, Float> metricCounts = new HashMap<>();
        AbstractMetricsBolt bolt = getBolt();

        outputCollector = new MockOutputCollector();

        // Prepare the bolt so that it uses our mock output collector
        bolt.prepare(null, null, new OutputCollector(outputCollector));

        // Emit all events
View Full Code Here

        MongoClient mongoClient = new MongoClient(MongoClient.BUSINESSDB_CONFIG_ID);
        List<BasicDBObject> connections = mongoClient.getConnections();

        for (BasicDBObject connection : connections) {
            InternalConnectionInventoryBolt bolt = new InternalConnectionInventoryBolt();
            MockOutputCollector outputCollector = new MockOutputCollector();
            Tuple tuple = mock(Tuple.class);
            List<BasicDBObject> expectedInventoryItems = new ArrayList<>();
            String connectionId = connection.getString("_id");
            final String connectionType = connection.getString("type");

            when(tuple.getValue(0)).thenReturn(connection);

            bolt.prepare(null, null, new OutputCollector(outputCollector));

            bolt.execute(tuple);

            if (connectionType.equals(ConnectionTypeConstants.PROJECT_HOSTING_TYPE)) {
                expectedInventoryItems = mongoClient.getProjectHostingInventoryItems(connectionId);
            } else if (connectionType.equals(ConnectionTypeConstants.CLOUD_TYPE)) {
               expectedInventoryItems = mongoClient.getCloudInventoryItems(connectionId);
            }

            List<Values> emittedTuples = outputCollector.getEmittedValues();

            // Make sure all tuples are acked
            Assert.assertEquals(1, outputCollector.getAckedTuples().size());

            // Make sure the size of the emitted values is right
            Assert.assertEquals(expectedInventoryItems.size(), emittedTuples.size());

            Set<String> connectionTypesWithInventory = ImmutableSet.of(ConnectionTypeConstants.CLOUD_TYPE,
View Full Code Here

TOP

Related Classes of com.streamreduce.storm.MockOutputCollector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.