Example #1
0
        public void TestStringStream_Observed_Mapped_Copy()
        {
            ReplaySubject <string> subject = new ReplaySubject <string>();

            Stream <string> stream = new Stream <string>(subject.AsObservable());

            subject.OnNext("1");
            subject.OnNext("2");
            subject.OnNext("3");
            subject.OnNext("4");
            subject.OnNext("5");

            stream.Read();
            stream.Read();
            stream.Read();
            stream.SetOffset(3);
            // Add first mapping
            IStream <string> mappedStream1 = stream.Map(s => "map1_" + s);
            // Add second mapping
            IStream <string> mappedStream2 = mappedStream1.Map(s => "map2_" + s);
            // Add fanout
            IStream <string> output = mappedStream2.Copy();
            // read fanout and check all mappings are called
            string result = output.Read();

            Assert.AreEqual("map2_map1_4", result);
        }
Example #2
0
        public void TestStringStream_Observed_Replay_Mapped_Copy_InterruptedSupply()
        {
            ReplaySubject <string> subject = new ReplaySubject <string>();

            Stream <string> stream = new Stream <string>(subject.AsObservable());

            int mappingsHit = 0;

            IStream <string> mappedStream = stream.Map(s =>
            {
                Debug.WriteLine("mapping " + s);
                mappingsHit++;
                return("m" + s);
            });

            IStream <string> copyStream = mappedStream.Copy();

            for (int i = 0; i < 100; i++)
            {
                subject.OnNext(i.ToString());
            }

            for (int i = 0; i < 50; i++)
            {
                Assert.AreEqual("m" + i, copyStream.Read());
            }

            Assert.AreEqual(50, mappingsHit);

            for (int i = 100; i < 200; i++)
            {
                subject.OnNext(i.ToString());
            }

            for (int i = 50; i < 200; i++)
            {
                Assert.AreEqual("m" + i, copyStream.Read());
            }

            Assert.AreEqual(200, mappingsHit);

            Assert.AreEqual(200, copyStream.Count());
        }
Example #3
0
        public void TestStringStream_Observed_Replay_Mapped_Copy()
        {
            ReplaySubject <string> subject = new ReplaySubject <string>();

            Stream <string> stream = new Stream <string>(subject.AsObservable());

            IStream <int[]> mappedStream = stream.Map(s => new int[int.Parse(s)]);

            IStream <int[]> copyStream = mappedStream.Copy();

            subject.OnNext("1");

            Assert.IsTrue(new int[1].SequenceEqual(copyStream.Read()));

            subject.OnNext("2");

            Assert.IsTrue(new int[2].SequenceEqual(copyStream.Read()));

            Assert.AreEqual(2, copyStream.Count());
        }
Example #4
0
        public void TestStringStream_Yielding_Mapped_Copy()
        {
            string[] source = { "1", "2", "3", "4", "5" };

            Stream <string> stream = new Stream <string>(GetDataSourceYielding(source));

            stream.Read();
            stream.Read();
            stream.Read();
            stream.SetOffset(3);
            // Add first mapping
            IStream <string> mappedStream1 = stream.Map(s => "map1_" + s);
            // Add second mapping
            IStream <string> mappedStream2 = mappedStream1.Map(s => "map2_" + s);
            // Add fanout
            IStream <string> output = mappedStream2.Copy();
            // read fanout and check all mappings are called
            string result = output.Read();

            Assert.AreEqual("map2_map1_4", result);
        }
Example #5
0
        /// <summary>
        /// Returns the encoded output stream of the underlying <see cref="IStream{T}"/>'s encoder.
        /// </summary>
        /// <returns>the encoded output stream.</returns>
        public IStream <int[]> GetOutputStream()
        {
            if (IsTerminal())
            {
                throw new InvalidOperationException("Stream is already \"terminal\" (operated upon or empty)");
            }

            MultiEncoder encoder = (MultiEncoder)GetEncoder();

            if (encoder == null)
            {
                throw new InvalidOperationException("setLocalParameters(Parameters) must be called before calling this method.");
            }

            // Protect outputStream formation and creation of "fan out" also make sure
            // that no other thread is trying to update the fan out lists
            IStream <int[]> retVal = null;

            try
            {
                System.Threading.Monitor.Enter(_criticalAccessLock);

                string[]        fieldNames = GetFieldNames();
                FieldMetaType[] fieldTypes = GetFieldTypes();

                if (outputStream == null)
                {
                    if (!indexFieldMap.Any())
                    {
                        for (int i = 0; i < fieldNames.Length; i++)
                        {
                            indexFieldMap.Add(fieldNames[i], i);
                        }
                    }

                    // NOTE: The "inputMap" here is a special local implementation
                    //       of the "Map" interface, overridden so that we can access
                    //       the keys directly (without hashing). This map is only used
                    //       for this use case so it is ok to use this optimization as
                    //       a convenience.
                    if (inputMap == null)
                    {
                        inputMap        = new InputMap(this);
                        inputMap.fTypes = fieldTypes;
                    }

                    bool isParallel = @delegate.GetInputStream().IsParallel();

                    output = new List <int[]>();

                    IMetaStream     inputStream       = @delegate.GetInputStream();
                    IStream <int[]> mappedInputStream = ((IMetaStream <string[]>)inputStream).Map(i =>
                    {
                        //Debug.WriteLine(">> Calling HTM Sensor mapping");
                        string[] arr = i;
                        inputMap.arr = arr;
                        return(Input(arr, fieldNames, fieldTypes, output, isParallel));
                    });

                    outputStream = mappedInputStream;

                    //mainIterator = outputStream.GetEnumerator();
                }

                //LinkedList<int[]> l = new LinkedList<int[]>();
                //fanOuts.Add(l);

                //ObjectStreamCopier copy = new ObjectStreamCopier(this, l);
                //Copy copy = new Copy(this, l);
                //copy.Reset();
                //retVal = new Stream<int[]>(l, copy, outputStream.GetStreamState());
                retVal = outputStream.Copy();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                System.Threading.Monitor.Exit(_criticalAccessLock);
            }

            return(retVal);
        }
Example #6
0
 public FilterchainOutput Copy()
 {
     return(new FilterchainOutput(Owner, Stream.Copy()));
 }