Пример #1
0
        private static void CreateAndVerifyConnection(ISocketWrapper daemonSocket)
        {
            var            ipEndpoint   = (IPEndPoint)daemonSocket.LocalEndPoint;
            int            port         = ipEndpoint.Port;
            ISocketWrapper clientSocket = SocketFactory.CreateSocket();

            clientSocket.Connect(ipEndpoint.Address, port);

            // Now process the bytes flowing in from the client.
            PayloadWriter payloadWriter = new PayloadWriterFactory().Create();

            payloadWriter.WriteTestData(clientSocket.OutputStream);
            List <object[]> rowsReceived = PayloadReader.Read(clientSocket.InputStream);

            // Validate rows received.
            Assert.Equal(10, rowsReceived.Count);

            for (int i = 0; i < 10; ++i)
            {
                // Two UDFs registered, thus expecting two columns.
                // Refer to TestData.GetDefaultCommandPayload().
                object[] row = rowsReceived[i];
                Assert.Equal(2, rowsReceived[i].Length);
                Assert.Equal($"udf2 udf1 {i}", row[0]);
                Assert.Equal(i + i, row[1]);
            }
        }
Пример #2
0
        internal static void TestTaskRunnerReadWrite(
            ISocketWrapper serverListener,
            PayloadWriter payloadWriter)
        {
            using (ISocketWrapper serverSocket = serverListener.Accept())
            {
                System.IO.Stream inputStream  = serverSocket.InputStream;
                System.IO.Stream outputStream = serverSocket.OutputStream;

                payloadWriter.WriteTestData(outputStream);
                // Now process the bytes flowing in from the client.
                List <object[]> rowsReceived = PayloadReader.Read(inputStream);

                // Validate rows received.
                Assert.Equal(10, rowsReceived.Count);
                for (int i = 0; i < 10; ++i)
                {
                    // Two UDFs registered, thus expecting two columns.
                    // Refer to TestData.GetDefaultCommandPayload().
                    object[] row = rowsReceived[i];
                    Assert.Equal(2, rowsReceived[i].Length);
                    Assert.Equal($"udf2 udf1 {i}", row[0]);
                    Assert.Equal(i + i, row[1]);
                }
            }
        }
Пример #3
0
        public void TestTaskRunner()
        {
            using var serverListener = new DefaultSocketWrapper();
            serverListener.Listen();

            var port         = (serverListener.LocalEndPoint as IPEndPoint).Port;
            var clientSocket = new DefaultSocketWrapper();

            clientSocket.Connect(IPAddress.Loopback, port, null);

            PayloadWriter payloadWriter = new PayloadWriterFactory().Create();
            var           taskRunner    = new TaskRunner(0, clientSocket, false, payloadWriter.Version);
            Task          clientTask    = Task.Run(() => taskRunner.Run());

            using (ISocketWrapper serverSocket = serverListener.Accept())
            {
                System.IO.Stream inputStream  = serverSocket.InputStream;
                System.IO.Stream outputStream = serverSocket.OutputStream;

                payloadWriter.WriteTestData(outputStream);
                // Now process the bytes flowing in from the client.
                List <object[]> rowsReceived = PayloadReader.Read(inputStream);

                // Validate rows received.
                Assert.Equal(10, rowsReceived.Count);
                for (int i = 0; i < 10; ++i)
                {
                    // Two UDFs registered, thus expecting two columns.
                    // Refer to TestData.GetDefaultCommandPayload().
                    object[] row = rowsReceived[i];
                    Assert.Equal(2, rowsReceived[i].Length);
                    Assert.Equal($"udf2 udf1 {i}", row[0]);
                    Assert.Equal(i + i, row[1]);
                }
            }

            Assert.True(clientTask.Wait(5000));
        }