/// <summary>
        /// Here is a example to test the topology as a standalone console application.
        /// "LocalContext" is a local-mode SCP Context which is used to initialize a component,
        /// and each components communicate by using a plain text file.
        /// </summary>
        public void RunTestCase()
        {
            Dictionary <string, Object> emptyDictionary = new Dictionary <string, object>();
            Dictionary <string, Object> boltParms       = new Dictionary <string, object>();

            StormTxAttempt txAttempt = new StormTxAttempt();

            txAttempt.TxId      = 1;
            txAttempt.AttemptId = 1;
            boltParms[Constants.STORM_TX_ATTEMPT] = txAttempt;

            {
                // create a "Generator" object
                LocalContext generatorCtx = LocalContext.Get();
                Generator    generator    = Generator.Get(generatorCtx, emptyDictionary);

                // call nextTx()
                long seqId;
                generator.NextTx(out seqId, emptyDictionary);

                // write the messages in memory to files
                generatorCtx.WriteMsgQueueToFile("generator.txt");
            }

            {
                LocalContext partialCountCtx = LocalContext.Get();
                PartialCount partialCount    = PartialCount.Get(partialCountCtx, boltParms);

                partialCountCtx.ReadFromFileToMsgQueue("generator.txt");
                List <SCPTuple> batch = partialCountCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    partialCount.Execute(tuple);
                }
                partialCount.FinishBatch(emptyDictionary);
                partialCountCtx.WriteMsgQueueToFile("partial-count.txt");
            }

            {
                LocalContext countSumCtx = LocalContext.Get();
                CountSum     countSum    = CountSum.Get(countSumCtx, boltParms);

                countSumCtx.ReadFromFileToMsgQueue("partial-count.txt");
                List <SCPTuple> batch = countSumCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    countSum.Execute(tuple);
                }
                countSum.FinishBatch(emptyDictionary);
                countSumCtx.WriteMsgQueueToFile("count-sum.txt");
            }
        }
        public static void Run()
        {
            Console.WriteLine(CLASS_NAME + "run");

            Dictionary <string, Object> parms = new Dictionary <string, object>();

            {
                LocalContext spoutCtx = LocalContext.Get();
                var          spout    = IISLogGeneratorSpout.Get(spoutCtx, parms);

                for (int i = 0; i < 10; i++)
                {
                    spout.NextTuple(parms);
                }
                spoutCtx.WriteMsgQueueToFile(CLASS_NAME + "spout.out");
            }

            parms.Add("inputSchema", IISLogGeneratorSpout.OutputFieldTypes);

            {
                LocalContext boltCtx = LocalContext.Get();
                var          bolt    = LoggerBolt.Get(boltCtx, parms);
                boltCtx.ReadFromFileToMsgQueue(CLASS_NAME + "spout.out");
                List <SCPTuple> batch = boltCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    bolt.Execute(tuple);
                }
                boltCtx.WriteMsgQueueToFile(CLASS_NAME + "logger.out");
            }

            {
                LocalContext boltCtx = LocalContext.Get();
                var          bolt    = SqlAzureBolt.Get(boltCtx, parms);
                boltCtx.ReadFromFileToMsgQueue(CLASS_NAME + "spout.out");
                List <SCPTuple> batch = boltCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    bolt.Execute(tuple);
                }
                boltCtx.WriteMsgQueueToFile(CLASS_NAME + "bolt.out");
            }
        }
Exemple #3
0
        /// <summary>
        /// Here is an example to test the topology as a standalone console application, so users could validate the logic in the C# code.
        /// This is available to a topology with only C# spouts and bolts.
        /// If you want to use the local test mode provided by SCP.NET, you must change the project output type to "Console Application",
        /// and add a Main function.
        /// For more information, please refer to the document: http://go.microsoft.com/fwlink/?LinkId=525649
        /// In this example, "LocalContext" is a local-mode SCP Context which is used to initialize a component,
        /// and each component communicates by using a plain text file.
        /// </summary>

        public void RunTestCase()
        {
            Dictionary <string, Object> emptyDictionary = new Dictionary <string, object>();

            {
                LocalContext generatorCtx = LocalContext.Get();
                Generator    generator    = Generator.Get(generatorCtx, emptyDictionary);

                for (int i = 0; i < 10; i++)
                {
                    generator.NextTuple(emptyDictionary);
                }
                generatorCtx.WriteMsgQueueToFile("generator.txt");
            }

            {
                LocalContext splitterCtx = LocalContext.Get();
                Splitter     splitter    = Splitter.Get(splitterCtx, emptyDictionary);

                splitterCtx.ReadFromFileToMsgQueue("generator.txt");
                List <SCPTuple> batch = splitterCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    splitter.Execute(tuple);
                }
                splitterCtx.WriteMsgQueueToFile("splitter.txt");
            }

            {
                LocalContext counterCtx = LocalContext.Get();
                Counter      counter    = Counter.Get(counterCtx, emptyDictionary);

                counterCtx.ReadFromFileToMsgQueue("splitter.txt");
                List <SCPTuple> batch = counterCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    counter.Execute(tuple);
                }
                counterCtx.WriteMsgQueueToFile("counter.txt");
            }
        }
Exemple #4
0
        // Drives the topology components
        public void RunTestCase()
        {
            // An empty dictionary for use when creating components
            Dictionary <string, Object> emptyDictionary = new Dictionary <string, object>();

            #region Test the spout
            {
                Console.WriteLine("Starting spout");
                // LocalContext is a local-mode context that can be used to initialize
                // components in the development environment.
                LocalContext spoutCtx = LocalContext.Get();
                // Get a new instance of the spout, using the local context
                Spout sentences = Spout.Get(spoutCtx, emptyDictionary);

                // Emit 10 tuples
                for (int i = 0; i < 10; i++)
                {
                    sentences.NextTuple(emptyDictionary);
                }
                // Use LocalContext to persist the data stream to file
                spoutCtx.WriteMsgQueueToFile("sentences.txt");
                Console.WriteLine("Spout finished");
            }
            #endregion

            #region Test the splitter bolt
            {
                Console.WriteLine("Starting splitter bolt");
                // LocalContext is a local-mode context that can be used to initialize
                // components in the development environment.
                LocalContext splitterCtx = LocalContext.Get();
                // Get a new instance of the bolt
                Splitter splitter = Splitter.Get(splitterCtx, emptyDictionary);

                // Set the data stream to the data created by the spout
                splitterCtx.ReadFromFileToMsgQueue("sentences.txt");
                // Get a batch of tuples from the stream
                List <SCPTuple> batch = splitterCtx.RecvFromMsgQueue();
                // Process each tuple in the batch
                foreach (SCPTuple tuple in batch)
                {
                    splitter.Execute(tuple);
                }
                // Use LocalContext to persist the data stream to file
                splitterCtx.WriteMsgQueueToFile("splitter.txt");
                Console.WriteLine("Splitter bolt finished");
            }
            #endregion

            #region Test the counter bolt
            {
                Console.WriteLine("Starting counter bolt");
                // LocalContext is a local-mode context that can be used to initialize
                // components in the development environment.
                LocalContext counterCtx = LocalContext.Get();
                // Get a new instance of the bolt
                Counter counter = Counter.Get(counterCtx, emptyDictionary);

                // Set the data stream to the data created by splitter bolt
                counterCtx.ReadFromFileToMsgQueue("splitter.txt");
                // Get a batch of tuples from the stream
                List <SCPTuple> batch = counterCtx.RecvFromMsgQueue();
                // Process each tuple in the batch
                foreach (SCPTuple tuple in batch)
                {
                    counter.Execute(tuple);
                }
                // Use LocalContext to persist the data stream to file
                counterCtx.WriteMsgQueueToFile("counter.txt");
                Console.WriteLine("Counter bolt finished");
            }
            #endregion
        }
Exemple #5
0
        //Run tests
        public void RunTestCase()
        {
            var hubConnection   = new Microsoft.AspNet.SignalR.Client.HubConnection("http://tweetsentiment.azurewebsites.net/");
            var twitterHubProxy = hubConnection.CreateHubProxy("TwitterHub");

            hubConnection.Start().Wait();

            for (int i = 0; i < 100000; i++)
            {
                twitterHubProxy.Invoke("UpdateCounter", i);
                Thread.Sleep(50);
            }


            Dictionary <string, Object> emptyDictionary = new Dictionary <string, object>();
            //Spout tests
            {
                //Get local context
                LocalContext spoutCtx = LocalContext.Get();
                //Get an instance of the spout
                TwitterSpout spout = TwitterSpout.Get(spoutCtx, emptyDictionary);

                // Collect some tweets
                Thread.Sleep(5000);

                //Call NextTuple to emit data
                for (int i = 0; i < 10; i++)
                {
                    spout.NextTuple(emptyDictionary);
                }
                //Store the stream for the next component
                spoutCtx.WriteMsgQueueToFile("spout.txt");
                spout.StopListenerThread();
            }

            //HBaseWriterBolt tests
            //{
            //    LocalContext splitterCtx = LocalContext.Get();
            //    HBaseWriterBolt splitter = HBaseWriterBolt.Get(splitterCtx, emptyDictionary);
            //    //Read from the 'stream' emitted by the spout
            //    splitterCtx.ReadFromFileToMsgQueue("spout.txt");
            //    List<SCPTuple> batch = splitterCtx.RecvFromMsgQueue();
            //    foreach (SCPTuple tuple in batch.Take(batch.Count - 1))
            //    {
            //        splitter.Execute(tuple);
            //    }
            //    Thread.Sleep(100);
            //    splitter.Execute(batch.Last());
            //}

            //HBaseCounterBolt tests
            {
                LocalContext     counterCtx = LocalContext.Get();
                HBaseCounterBolt counter    = HBaseCounterBolt.Get(counterCtx, emptyDictionary);
                //Read from the 'stream' emitted by the spout
                counterCtx.ReadFromFileToMsgQueue("spout.txt");
                List <SCPTuple> batch = counterCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch.Take(batch.Count - 1))
                {
                    counter.Execute(tuple);
                }
                Thread.Sleep(100);
                counter.Execute(batch.Last());
                counterCtx.WriteMsgQueueToFile("counter.txt");
            }

            //SignalRBroadcastBolt tests
            {
                LocalContext         broadcastCtx = LocalContext.Get();
                SignalRBroadcastBolt broadcast    = SignalRBroadcastBolt.Get(broadcastCtx, emptyDictionary);
                //Read from the 'stream' emitted by the spout
                broadcastCtx.ReadFromFileToMsgQueue("counter.txt");
                List <SCPTuple> batch = broadcastCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    broadcast.Execute(tuple);
                }
            }
        }