Example #1
0
 internal static void ck(IO.Buffer b, long got, long expected)
 {
     if (expected != got)
     {
         fail(b, expected, got);
     }
 }
Example #2
0
        public static unsafe void TestParquetReadFromBuffer()
        {
            var expected = Enumerable.Range(0, 100).ToArray();

            // Write out a single column
            byte[] parquetFileBytes;
            using (var outBuffer = new ResizableBuffer())
            {
                using (var outStream = new BufferOutputStream(outBuffer))
                    using (var fileWriter = new ParquetFileWriter(outStream, new Column[] { new Column <int>("int_field") }))
                        using (var rowGroupWriter = fileWriter.AppendRowGroup())
                            using (var colWriter = rowGroupWriter.NextColumn().LogicalWriter <int>())
                            {
                                colWriter.WriteBatch(expected);
                            }

                parquetFileBytes = outBuffer.ToArray();
            }

            // Read it back
            fixed(byte *fixedBytes = parquetFileBytes)
            using (var buffer = new IO.Buffer(new IntPtr(fixedBytes), parquetFileBytes.Length))
                using (var inStream = new BufferReader(buffer))
                    using (var fileReader = new ParquetFileReader(inStream))
                        using (var rowGroup = fileReader.RowGroup(0))
                            using (var columnReader = rowGroup.Column(0).LogicalReader <int>())
                            {
                                var allData = columnReader.ReadAll((int)rowGroup.MetaData.NumRows);
                                Assert.AreEqual(expected, allData);
                            }
        }
        private void SendBuffer(IO.Buffer buffer, TPacket packet)
        {
            SocketError error;

            try
            {
                socket.Send(buffer.data, 0, buffer.size, SocketFlags.None, out error);
            }
            catch (Exception e)
            {
                Log.Error(e);
                error = SocketError.Disconnecting;
            }

            if (CheckError(error))
            {
                Log.Error("SocketError received on Send: " + error);
                if (packet is ITokenPacket token && !token.TokenResponse)
                {
                    tokenCallbacks.TryRemove(token.Token, out var dummy);
                }
                Disconnect();
                return;
            }
        }
Example #4
0
        /// <summary>
        /// Initializes the socket for catching incoming connections
        /// </summary>
        private void InitSocket()
        {
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            socket.Bind(new IPEndPoint(IPAddress.Any, port));

            buffer = new IO.Buffer(512);
        }
Example #5
0
 internal static void ck(IO.Buffer b, bool cond)
 {
     if (!cond)
     {
         fail("Condition failed", b);
     }
 }
Example #6
0
 internal static void fail(IO.Buffer b,
                           string expected, char expectedChar,
                           string got, char gotChar)
 {
     if (b is ByteBuffer)
     {
         ByteBuffer bb = (ByteBuffer)b;
         int        n  = Math.Min(16, bb.Limit);
         for (int i = 0; i < n; i++)
         {
             output.Write(" " + (bb.Get(i) & 0xff).ToString("x4", CultureInfo.InvariantCulture));
         }
         output.WriteLine();
     }
     //if (b is CharBuffer) {
     //    CharBuffer bb = (CharBuffer)b;
     //    int n = Math.Min(16, bb.Limit);
     //    for (int i = 0; i < n; i++)
     //        output.Write(" " + (bb.get(i) & 0xffff).ToString("x4", CultureInfo.InvariantCulture));
     //    output.WriteLine();
     //}
     Assert.Fail(ToString(b)
                 + ": Expected '" + expectedChar + "'=0x"
                 + expected
                 + ", got '" + gotChar + "'=0x"
                 + got);
 }
Example #7
0
 internal static void Show(int level, IO.Buffer b)
 {
     for (int i = 0; i < level; i++)
     {
         output.Write("  ");
     }
     output.WriteLine(ToString(b) + " " + b.GetHashCode().ToString("x4", CultureInfo.InvariantCulture));
 }
Example #8
0
 internal static string ToString(IO.Buffer b)
 {
     return(b.GetType().Name
            + "[pos=" + b.Position
            + " lim=" + b.Limit
            + " cap=" + b.Capacity
            + "]");
 }
 private static void checkInvalidMarkException(IO.Buffer b)
 {
     tryCatch(b, typeof(InvalidMarkException), () =>
     {
         b.Mark();
         compact(b);
         b.Reset();
     });
 }
Example #10
0
 internal static void ck(IO.Buffer b, double got, double expected)
 {
     if (expected != got)
     {
         fail(b,
              expected.ToString("0.0##########", CultureInfo.InvariantCulture), (char)expected,
              got.ToString("0.0##########", CultureInfo.InvariantCulture), (char)got);
     }
 }
Example #11
0
        public static unsafe void TestMemoryBufferRoundtrip()
        {
            var expected = Enumerable.Range(0, 100).Select(i => (byte)i).ToArray();

            fixed(byte *data = expected)
            {
                using var buffer = new IO.Buffer(new IntPtr(data), expected.Length);
                Assert.AreEqual(expected, buffer.ToArray());
            }
        }
 private static void compact(IO.Buffer b)
 {
     try
     {
         Type       cl = b.GetType();
         MethodInfo m  = cl.GetMethod("Compact", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
         m.Invoke(b, new object[0]);
     }
     catch (Exception e)
     {
         fail(e.ToString(), b);
     }
 }
Example #13
0
 private void DoSendData(IO.Buffer package)
 {
     //var ip = (IPEndPoint)remoteEndPoint;
     //Log.Write("Sending to: " + ip.Address + ":" + ip.Port + " From port: " + LocalPort);
     try
     {
         socket.BeginSendTo(package.data, 0, package.size, SocketFlags.None, remoteEndPoint, OnSend, null);
     }
     catch (ObjectDisposedException)
     {
         Disconnect(UdpDisconnectReason.Custom, true, "Begin send object disposed exception");
         return;
     }
 }
Example #14
0
        private void Init()
        {
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 1000);

            packetFactory = new PacketFactory <TPacket>();
            buffer        = new IO.Buffer(Max_Packet_Size);

            timer          = new System.Timers.Timer(Connection_Retry_Delay / 2);
            timer.Elapsed += OnTimer;

            defaultChannel = new UnreliableChannel <TPacket>();
            ConfigurePacketChannel(defaultChannel);

            channels = new PacketChannel <TPacket> [packetFactory.TypeCount + 1];
            for (int i = 0; i < channels.Length; i++)
            {
                channels[i] = defaultChannel; // set every channel to the default
            }
        }
        private static void tryCatch(IO.Buffer b, Type ex, Action thunk)
        {
            bool caught = false;

            try
            {
                thunk();
            }
            catch (Exception x)
            {
                if (ex.GetTypeInfo().IsAssignableFrom(x.GetType()))
                {
                    caught = true;
                }
                else
                {
                    fail(x.Message + " not expected");
                }
            }
            if (!caught)
            {
                fail(ex.Name + " not thrown", b);
            }
        }
 private void Init()
 {
     packetFactory  = new PacketFactory <TPacket>();
     socket.NoDelay = true;
     buffer         = new IO.Buffer(4);
 }
Example #17
0
        //static void fail(string s)
        //{
        //    Assert.Fail(s);
        //}

        internal static void fail(string s, IO.Buffer b)
        {
            fail(s + ": " + ToString(b));
        }
Example #18
0
 internal static void fail(IO.Buffer b, long expected, long got)
 {
     fail(b,
          (expected).ToString("x4", CultureInfo.InvariantCulture), (char)expected,
          (got).ToString("x4", CultureInfo.InvariantCulture), (char)got);
 }
Example #19
0
 internal static void fail(String s, IO.Buffer b, IO.Buffer b2)
 {
     fail(s + ": "
          + ToString(b) + ", " + ToString(b2));
 }