예제 #1
0
        public void TestSensorTerminalOperationDetection()
        {
            Sensor <FileInfo> sensor = Sensor <FileInfo> .Create(
                FileSensor.Create,
                SensorParams.Create(
                    SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-small.Csv")));

            HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor;

            // We haven't done anything with the stream yet, so it should not be terminal
            Assert.IsFalse(htmSensor.IsTerminal());
            ((BatchedCsvStream <string[]>)htmSensor.GetInputStream()).ForEach(l => Console.WriteLine(Arrays.ToString((string[])l)));
            // Should now be terminal after operating on the stream
            Assert.IsTrue(htmSensor.IsTerminal());
        }
예제 #2
0
        public void TestSensorMultipleStreamCreation()
        {
            Sensor <FileInfo> sensor = Sensor <FileInfo> .Create(
                FileSensor.Create,
                SensorParams.Create(
                    SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-small.Csv")));

            HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor;

            htmSensor.InitEncoder(GetTestEncoderParams());

            // Ensure that the HTMSensor's output stream can be retrieved more than once.
            IStream <int[]> outputStream  = htmSensor.GetOutputStream();
            IStream <int[]> outputStream2 = htmSensor.GetOutputStream();
            IStream <int[]> outputStream3 = htmSensor.GetOutputStream();

            // Check to make sure above multiple retrieval doesn't flag the underlying stream as operated upon
            Assert.IsFalse(htmSensor.IsTerminal());
            Assert.AreEqual(17, outputStream.Count());

            //After the above we cannot request a new stream, so this will fail
            //however, the above streams that were already requested should be unaffected.
            Assert.IsTrue(htmSensor.IsTerminal(), "Terminal sensor stream expected");
            try
            {
                //@SuppressWarnings("unused")
                IStream <int[]> outputStream4 = (Stream <int[]>)htmSensor.GetOutputStream();
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Stream is already \"terminal\" (operated upon or empty)", e.Message);
            }

            //These Streams were created before operating on a stream
            Assert.AreEqual(17, outputStream2.Count());
            Assert.AreEqual(17, outputStream3.Count());

            // Verify that different streams are retrieved.
            Assert.IsFalse(outputStream.GetHashCode() == outputStream2.GetHashCode());
            Assert.IsFalse(outputStream2.GetHashCode() == outputStream3.GetHashCode());
        }