Пример #1
0
        private static string Stringify(IntWritable key, Writable val)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(" + key);
            sb.Append("," + val + ")");
            return(sb.ToString());
        }
        /// <summary>Initialize the channel.</summary>
        /// <param name="runContinuationsAsynchronously">Whether to force continuations to be executed asynchronously.</param>
        internal SingleConsumerUnboundedChannel(bool runContinuationsAsynchronously)
        {
            _runContinuationsAsynchronously = runContinuationsAsynchronously;
            _completion = new TaskCompletionSource <VoidResult>(runContinuationsAsynchronously ? TaskCreationOptions.RunContinuationsAsynchronously : TaskCreationOptions.None);

            In  = new Readable(this);
            Out = new Writable(this);
        }
Пример #3
0
 /// <summary>Create a value to be used internally for joins.</summary>
 protected internal virtual TupleWritable CreateInternalValue()
 {
     Writable[] vals = new Writable[kids.Length];
     for (int i = 0; i < vals.Length; ++i)
     {
         vals[i] = kids[i].CreateValue();
     }
     return(new TupleWritable(vals));
 }
Пример #4
0
        /// <summary>
        /// read name=value attrbute
        /// </summary>
        /// <returns></returns>
        public Attribute ReadAttribute()
        {
            Writable name, value;

            name = new Writable(ReadString());
            Read(); // = char
            value = new Writable(ReadQuoteString());
            return(new Attribute(name, value));
        }
Пример #5
0
 private Writable[] MakeRandomWritables(int numWrits)
 {
     Writable[] writs     = MakeRandomWritables();
     Writable[] manyWrits = new Writable[numWrits];
     for (int i = 0; i < manyWrits.Length; i++)
     {
         manyWrits[i] = writs[i % writs.Length];
     }
     return(manyWrits);
 }
Пример #6
0
 /// <summary>Initializes the <see cref="BoundedChannel{T}"/>.</summary>
 /// <param name="bufferedCapacity">The positive bounded capacity for the channel.</param>
 /// <param name="mode">The mode used when writing to a full channel.</param>
 /// <param name="runContinuationsAsynchronously">Whether to force continuations to be executed asynchronously.</param>
 internal BoundedChannel(int bufferedCapacity, BoundedChannelFullMode mode, bool runContinuationsAsynchronously)
 {
     Debug.Assert(bufferedCapacity > 0);
     _bufferedCapacity = bufferedCapacity;
     _mode             = mode;
     _runContinuationsAsynchronously = runContinuationsAsynchronously;
     _completion = new TaskCompletionSource <VoidResult>(runContinuationsAsynchronously ? TaskCreationOptions.RunContinuationsAsynchronously : TaskCreationOptions.None);
     In          = new Readable(this);
     Out         = new Writable(this);
 }
Пример #7
0
        private Writable[] MakeRandomWritables()
        {
            Random r = new Random();

            Writable[] writs = new Writable[] { new BooleanWritable(r.NextBoolean()), new FloatWritable
                                                    (r.NextFloat()), new FloatWritable(r.NextFloat()), new IntWritable(r.Next()), new
                                                LongWritable(r.NextLong()), new BytesWritable(Sharpen.Runtime.GetBytesForString(
                                                                                                  "dingo")), new LongWritable(r.NextLong()), new IntWritable(r.Next()), new BytesWritable
                                                    (Sharpen.Runtime.GetBytesForString("yak")), new IntWritable(r.Next()) };
            return(writs);
        }
Пример #8
0
 // Mapper that sleeps for a long time.
 // Used for running a job that will be killed
 /// <exception cref="System.IO.IOException"/>
 protected override void Map <_T0>(WritableComparable <_T0> key, Writable value, Mapper.Context
                                   context)
 {
     try
     {
         Sharpen.Thread.Sleep(1000000);
     }
     catch (Exception)
     {
     }
 }
Пример #9
0
 public IWritable CreateWritable(
     [InputPin(PropertyMode = PropertyMode.Allow)] string data,
     [InputPin(PropertyMode = PropertyMode.Default)] Encoding encoding = null
     )
 {
     return(Writable.Create(async(destination, cancel) =>
     {
         using (var sw = new StreamWriter(destination, encoding ?? Encoding.UTF8, 512, true))
         {
             await sw.WriteAsync(data).ConfigureAwait(false);
         }
     }));
 }
Пример #10
0
        /// <exception cref="System.Exception"/>
        public virtual void TestNestedIterable()
        {
            Random r = new Random();

            Writable[] writs = new Writable[] { new BooleanWritable(r.NextBoolean()), new FloatWritable
                                                    (r.NextFloat()), new FloatWritable(r.NextFloat()), new IntWritable(r.Next()), new
                                                LongWritable(r.NextLong()), new BytesWritable(Sharpen.Runtime.GetBytesForString(
                                                                                                  "dingo")), new LongWritable(r.NextLong()), new IntWritable(r.Next()), new BytesWritable
                                                    (Sharpen.Runtime.GetBytesForString("yak")), new IntWritable(r.Next()) };
            TupleWritable sTuple = MakeTuple(writs);

            NUnit.Framework.Assert.IsTrue("Bad count", writs.Length == VerifIter(writs, sTuple
                                                                                 , 0));
        }
Пример #11
0
 public static IWritable EncodeBitmap(
     [InputPin(PropertyMode = PropertyMode.Never)] SKBitmap bitmap,
     [InputPin(PropertyMode = PropertyMode.Default)] SKEncodedImageFormat format = SKEncodedImageFormat.Png,
     [InputPin(PropertyMode = PropertyMode.Default)] int quality = 95
     )
 {
     return(Writable.Create(stream =>
     {
         using (var skStream = new SKManagedWStream(stream))
         {
             SKPixmap.Encode(skStream, bitmap, format, quality);
         }
     }));
 }
Пример #12
0
        /// <summary>Utility method for testing writables.</summary>
        /// <exception cref="System.Exception"/>
        public static Writable TestWritable(Writable before, Configuration conf)
        {
            DataOutputBuffer dob = new DataOutputBuffer();

            before.Write(dob);
            DataInputBuffer dib = new DataInputBuffer();

            dib.Reset(dob.GetData(), dob.GetLength());
            Writable after = (Writable)ReflectionUtils.NewInstance(before.GetType(), conf);

            after.ReadFields(dib);
            Assert.Equal(before, after);
            return(after);
        }
Пример #13
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        /// <exception cref="InstantiationException"/>
        /// <exception cref="System.MemberAccessException"/>
        private static void SequenceFileCodecTest(Configuration conf, int lines, string codecClass
                                                  , int blockSize)
        {
            Path filePath = new Path("SequenceFileCodecTest." + codecClass);

            // Configuration
            conf.SetInt("io.seqfile.compress.blocksize", blockSize);
            // Create the SequenceFile
            FileSystem fs = FileSystem.Get(conf);

            Log.Info("Creating SequenceFile with codec \"" + codecClass + "\"");
            SequenceFile.Writer writer = SequenceFile.CreateWriter(fs, conf, filePath, typeof(
                                                                       Text), typeof(Text), SequenceFile.CompressionType.Block, (CompressionCodec)System.Activator.CreateInstance
                                                                       (Runtime.GetType(codecClass)));
            // Write some data
            Log.Info("Writing to SequenceFile...");
            for (int i = 0; i < lines; i++)
            {
                Text key   = new Text("key" + i);
                Text value = new Text("value" + i);
                writer.Append(key, value);
            }
            writer.Close();
            // Read the data back and check
            Log.Info("Reading from the SequenceFile...");
            SequenceFile.Reader reader  = new SequenceFile.Reader(fs, filePath, conf);
            Writable            key_1   = (Writable)System.Activator.CreateInstance(reader.GetKeyClass());
            Writable            value_1 = (Writable)System.Activator.CreateInstance(reader.GetValueClass
                                                                                        ());
            int lc = 0;

            try
            {
                while (reader.Next(key_1, value_1))
                {
                    Assert.Equal("key" + lc, key_1.ToString());
                    Assert.Equal("value" + lc, value_1.ToString());
                    lc++;
                }
            }
            finally
            {
                reader.Close();
            }
            Assert.Equal(lines, lc);
            // Delete temporary files
            fs.Delete(filePath, false);
            Log.Info("SUCCESS! Completed SequenceFileCodecTest with codec \"" + codecClass +
                     "\"");
        }
Пример #14
0
 /// <exception cref="System.IO.IOException"/>
 public override Writable Call(RPC.RpcKind rpcKind, string protocol, Writable param
                               , long receiveTime)
 {
     if (sleep)
     {
         try
         {
             Thread.Sleep(Random.Next(20));
         }
         catch (Exception)
         {
         }
     }
     // sleep a bit
     return(param);
 }
Пример #15
0
        public virtual void TestReaderKeyIteration()
        {
            string TestMethodKey = "testReaderKeyIteration.mapfile";
            int    Size          = 10;
            int    Iterations    = 5;

            MapFile.Writer writer = null;
            MapFile.Reader reader = null;
            try
            {
                writer = CreateWriter(TestMethodKey, typeof(IntWritable), typeof(Text));
                int start = 0;
                for (int i = 0; i < Size; i++)
                {
                    writer.Append(new IntWritable(i), new Text("Value:" + i));
                }
                writer.Close();
                reader = CreateReader(TestMethodKey, typeof(IntWritable));
                // test iteration
                Writable startValue = new Text("Value:" + start);
                int      i_1        = 0;
                while (i_1++ < Iterations)
                {
                    IntWritable key   = new IntWritable(start);
                    Writable    value = startValue;
                    while (reader.Next(key, value))
                    {
                        NUnit.Framework.Assert.IsNotNull(key);
                        NUnit.Framework.Assert.IsNotNull(value);
                    }
                    reader.Reset();
                }
                Assert.True("reader seek error !!!", reader.Seek(new IntWritable
                                                                     (Size / 2)));
                NUnit.Framework.Assert.IsFalse("reader seek error !!!", reader.Seek(new IntWritable
                                                                                        (Size * 2)));
            }
            catch (IOException)
            {
                NUnit.Framework.Assert.Fail("reader seek error !!!");
            }
            finally
            {
                IOUtils.Cleanup(null, writer, reader);
            }
        }
Пример #16
0
    public void Save()
    {
        string          s  = "";
        List <Writable> ws = new List <Writable>();

        for (int i = 0; i < trackedObjects.Length; i++)
        {
            GameObject go = trackedObjects[i];
            Writable   w  = new Writable(go.name, go.transform.position, go.transform.rotation);
            ws.Add(w);
        }
        SaveData sd = new SaveData(ws);

        s += JsonUtility.ToJson(sd);
        File.WriteAllText(presetName, s);
        Debug.Log("Config Written to " + presetName);
    }
Пример #17
0
        /// <exception cref="System.Exception"/>
        public virtual void TestIterable()
        {
            Random r = new Random();

            Writable[] writs = new Writable[] { new BooleanWritable(r.NextBoolean()), new FloatWritable
                                                    (r.NextFloat()), new FloatWritable(r.NextFloat()), new IntWritable(r.Next()), new
                                                LongWritable(r.NextLong()), new BytesWritable(Sharpen.Runtime.GetBytesForString(
                                                                                                  "dingo")), new LongWritable(r.NextLong()), new IntWritable(r.Next()), new BytesWritable
                                                    (Sharpen.Runtime.GetBytesForString("yak")), new IntWritable(r.Next()) };
            TupleWritable t = new TupleWritable(writs);

            for (int i = 0; i < 6; ++i)
            {
                t.SetWritten(i);
            }
            VerifIter(writs, t, 0);
        }
Пример #18
0
        /// <exception cref="System.Exception"/>
        public virtual void TestPreVersion21CompatibilityEmptyTuple()
        {
            Writable[] manyWrits = new Writable[0];
            TestTupleWritable.PreVersion21TupleWritable oldTuple = new TestTupleWritable.PreVersion21TupleWritable
                                                                       (manyWrits);
            // don't set any values written
            ByteArrayOutputStream @out = new ByteArrayOutputStream();

            oldTuple.Write(new DataOutputStream(@out));
            ByteArrayInputStream @in    = new ByteArrayInputStream(@out.ToByteArray());
            TupleWritable        dTuple = new TupleWritable();

            dTuple.ReadFields(new DataInputStream(@in));
            NUnit.Framework.Assert.IsTrue("Tuple writable is unable to read pre-0.21 versions of TupleWritable"
                                          , oldTuple.IsCompatible(dTuple));
            NUnit.Framework.Assert.AreEqual("All tuple data has not been read from the stream"
                                            , -1, @in.Read());
        }
Пример #19
0
        /// <summary>Utility method for testing VersionedWritables.</summary>
        /// <exception cref="System.Exception"/>
        public static void TestVersionedWritable(Writable before, Writable after)
        {
            DataOutputBuffer dob = new DataOutputBuffer();

            before.Write(dob);
            DataInputBuffer dib = new DataInputBuffer();

            dib.Reset(dob.GetData(), dob.GetLength());
            try
            {
                after.ReadFields(dib);
            }
            catch (VersionMismatchException vmme)
            {
                System.Console.Out.WriteLine("Good, we expected this:" + vmme);
                return;
            }
            throw new Exception("A Version Mismatch Didn't Happen!");
        }
Пример #20
0
        /// <exception cref="System.Exception"/>
        public virtual void TestWritable()
        {
            Random r = new Random();

            Writable[] writs = new Writable[] { new BooleanWritable(r.NextBoolean()), new FloatWritable
                                                    (r.NextFloat()), new FloatWritable(r.NextFloat()), new IntWritable(r.Next()), new
                                                LongWritable(r.NextLong()), new BytesWritable(Sharpen.Runtime.GetBytesForString(
                                                                                                  "dingo")), new LongWritable(r.NextLong()), new IntWritable(r.Next()), new BytesWritable
                                                    (Sharpen.Runtime.GetBytesForString("yak")), new IntWritable(r.Next()) };
            TupleWritable         sTuple = MakeTuple(writs);
            ByteArrayOutputStream @out   = new ByteArrayOutputStream();

            sTuple.Write(new DataOutputStream(@out));
            ByteArrayInputStream @in    = new ByteArrayInputStream(@out.ToByteArray());
            TupleWritable        dTuple = new TupleWritable();

            dTuple.ReadFields(new DataInputStream(@in));
            NUnit.Framework.Assert.IsTrue("Failed to write/read tuple", sTuple.Equals(dTuple)
                                          );
        }
Пример #21
0
 /// <exception cref="System.IO.IOException"/>
 private void ValidateKeyValue <_T0>(WritableComparable <_T0> k, Writable v, int tupleSize
                                     , bool firstTuple, bool secondTuple, TestJoinProperties.TestType ttype)
 {
     System.Console.Out.WriteLine("out k:" + k + " v:" + v);
     if (ttype.Equals(TestJoinProperties.TestType.OuterAssociativity))
     {
         ValidateOuterKeyValue((IntWritable)k, (TupleWritable)v, tupleSize, firstTuple, secondTuple
                               );
     }
     else
     {
         if (ttype.Equals(TestJoinProperties.TestType.InnerAssociativity))
         {
             ValidateInnerKeyValue((IntWritable)k, (TupleWritable)v, tupleSize, firstTuple, secondTuple
                                   );
         }
     }
     if (ttype.Equals(TestJoinProperties.TestType.InnerIdentity))
     {
         ValidateKeyValue_INNER_IDENTITY((IntWritable)k, (IntWritable)v);
     }
 }
Пример #22
0
        /// <exception cref="System.Exception"/>
        public virtual void TestWideTuple2()
        {
            Text emptyText = new Text("Should be empty");

            Writable[] values = new Writable[64];
            Arrays.Fill(values, emptyText);
            values[9] = new Text("Number 9");
            TupleWritable tuple = new TupleWritable(values);

            tuple.SetWritten(9);
            for (int pos = 0; pos < tuple.Size(); pos++)
            {
                bool has = tuple.Has(pos);
                if (pos == 9)
                {
                    NUnit.Framework.Assert.IsTrue(has);
                }
                else
                {
                    NUnit.Framework.Assert.IsFalse("Tuple position is incorrectly labelled as set: "
                                                   + pos, has);
                }
            }
        }
Пример #23
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void WriteObject(Writable obj, DataOutputStream stream
                                                    )
        {
            // For Text and BytesWritable, encode them directly, so that they end up
            // in C++ as the natural translations.
            DataOutputBuffer buffer = new DataOutputBuffer();

            if (obj is Text)
            {
                Text t   = (Text)obj;
                int  len = t.GetLength();
                WritableUtils.WriteVLong(stream, len);
                stream.Flush();
                stream.Write(t.GetBytes(), 0, len);
                stream.Flush();
            }
            else
            {
                if (obj is BytesWritable)
                {
                    BytesWritable b   = (BytesWritable)obj;
                    int           len = b.GetLength();
                    WritableUtils.WriteVLong(stream, len);
                    stream.Write(b.GetBytes(), 0, len);
                }
                else
                {
                    buffer.Reset();
                    obj.Write(buffer);
                    int length = buffer.GetLength();
                    WritableUtils.WriteVInt(stream, length);
                    stream.Write(buffer.GetData(), 0, length);
                }
            }
            stream.Flush();
        }
Пример #24
0
        /// <summary>Tests that we can write more than 64 values.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestWideTupleBoundary()
        {
            Text emptyText = new Text("Should not be set written");

            Writable[] values = new Writable[65];
            Arrays.Fill(values, emptyText);
            values[64] = new Text("Should be the only value set written");
            TupleWritable tuple = new TupleWritable(values);

            tuple.SetWritten(64);
            for (int pos = 0; pos < tuple.Size(); pos++)
            {
                bool has = tuple.Has(pos);
                if (pos == 64)
                {
                    NUnit.Framework.Assert.IsTrue(has);
                }
                else
                {
                    NUnit.Framework.Assert.IsFalse("Tuple position is incorrectly labelled as set: "
                                                   + pos, has);
                }
            }
        }
Пример #25
0
        private TupleWritable MakeTuple(Writable[] writs)
        {
            Writable[] sub1 = new Writable[] { writs[1], writs[2] };
            Writable[] sub3 = new Writable[] { writs[4], writs[5] };
            Writable[] sub2 = new Writable[] { writs[3], new TupleWritable(sub3), writs[6] };
            Writable[] vals = new Writable[] { writs[0], new TupleWritable(sub1), new TupleWritable
                                                   (sub2), writs[7], writs[8], writs[9] };
            // [v0, [v1, v2], [v3, [v4, v5], v6], v7, v8, v9]
            TupleWritable ret = new TupleWritable(vals);

            for (int i = 0; i < 6; ++i)
            {
                ret.SetWritten(i);
            }
            ((TupleWritable)sub2[1]).SetWritten(0);
            ((TupleWritable)sub2[1]).SetWritten(1);
            ((TupleWritable)vals[1]).SetWritten(0);
            ((TupleWritable)vals[1]).SetWritten(1);
            for (int i_1 = 0; i_1 < 3; ++i_1)
            {
                ((TupleWritable)vals[2]).SetWritten(i_1);
            }
            return(ret);
        }
Пример #26
0
 /// <summary>Initialize the channel.</summary>
 internal UnbufferedChannel()
 {
     In  = new Readable(this);
     Out = new Writable(this);
 }
Пример #27
0
 public void Clear()
 {
     Writable.Clear();
 }
Пример #28
0
 public void Add(T item)
 {
     Writable.Add(item);
 }
Пример #29
0
 public void RemoveAt(int index)
 {
     Writable.RemoveAt(index);
 }
Пример #30
0
 public bool Remove(T item)
 {
     return(Writable.Remove(item));
 }
 public void map(Object key, Writable value, Context context)