示例#1
0
        public void RPC_LoadTest_1k_Large()
        {
            ipcMaster = new RpcBuffer(ipcName, async(msgId, payload) =>
            {
            }, bufferCapacity: 1025 * 512);
            ipcSlave = new RpcBuffer(ipcName, (msgId, payload) =>
            {
                return(new byte[] { (byte)(payload[0] * payload[1]) });
            });

            var buf = new byte[1025 * 512];

            buf[0] = 3;
            buf[1] = 3;

            Stopwatch watch = Stopwatch.StartNew();

            // Send request to slave from master
            for (var i = 0; i < 1000; i++)
            {
                var result = ipcMaster.RemoteRequest(buf, 100);
                Assert.IsTrue(result.Success);
                Assert.AreEqual((3 * 3), result.Data[0]);
            }
            watch.Stop();

            Assert.IsTrue(watch.ElapsedMilliseconds < 2000);
        }
示例#2
0
        public void RPC_Statistics_Reset()
        {
            ipcMaster = new RpcBuffer(ipcName);
            ipcSlave  = new RpcBuffer(ipcName, (msgId, payload) =>
            {
                Assert.IsTrue(payload != null);
                Assert.IsTrue(payload.Length == 2);
                // Add the two bytes together
                return(BitConverter.GetBytes((payload[0] + payload[1])));
            });

            var result = ipcMaster.RemoteRequest(new byte[] { 123, 10 });

            Assert.IsTrue(result.Success);
            Assert.AreEqual((ulong)1, ipcMaster.Statistics.RequestsSent);
            Assert.AreEqual((ulong)1, ipcSlave.Statistics.RequestsReceived);
            Assert.AreEqual((ulong)1, ipcSlave.Statistics.ResponsesSent);
            Assert.AreEqual((ulong)1, ipcMaster.Statistics.ResponsesReceived);

            ipcMaster.Statistics.Reset();

            var empty = new RpcStatistics();

            Assert.AreEqual(empty.RequestsSent, ipcMaster.Statistics.RequestsSent);
            Assert.AreEqual(empty.ResponsesReceived, ipcMaster.Statistics.ResponsesReceived);
            Assert.AreEqual(empty.ReadingLastMessageSize, ipcMaster.Statistics.ReadingLastMessageSize);
            Assert.AreEqual(empty.WritingLastMessageSize, ipcMaster.Statistics.WritingLastMessageSize);
        }
示例#3
0
        public void RPC_LoadTest_NestedCalls()
        {
            ipcMaster = new RpcBuffer(ipcName, async(msgId, payload) =>
            {
                // Ask slave to multiply the two bytes
                return((await ipcMaster.RemoteRequestAsync(new byte[] { 3, 3 }).ConfigureAwait(false)).Data);
            });
            ipcSlave = new RpcBuffer(ipcName, (msgId, payload) =>
            {
                return(new byte[] { (byte)(payload[0] * payload[1]) });
            });

            Stopwatch watch = Stopwatch.StartNew();

            // Send request to master from slave
            for (var i = 0; i < 10; i++)
            {
                var result = ipcSlave.RemoteRequest(null, 30000);
                Assert.IsTrue(result.Success);
                Assert.AreEqual((3 * 3), result.Data[0]);
            }
            watch.Stop();

            Assert.IsTrue(watch.ElapsedMilliseconds < 1000);
        }
示例#4
0
        public async override Task <bool> SendToken(string jsonText)
        {
            var rpcGru         = new RpcBuffer(appName); //Soup told me not to but its funny
            var RPCresult      = rpcGru.RemoteRequest(Encoding.UTF8.GetBytes(jsonText));
            var MinionResponse = Encoding.UTF8.GetString(RPCresult.Data, 0, RPCresult.Data.Length);

            return(RPCresult.Success);
        }
示例#5
0
 public void Constructor_MasterSlave_Create()
 {
     ipcMaster = new RpcBuffer(ipcName, (msgId, payload) =>
     {
     });
     ipcSlave = new RpcBuffer(ipcName, (msgId, payload) =>
     {
     });
 }
示例#6
0
 public void RegisterMinion()
 {
     var rpcMinion = new RpcBuffer(appName, (msgId, payload) =>
     {
         var serverResponse = "Carbon has a huge pp also this is debug messages.";
         var gotData        = Encoding.UTF8.GetString(payload, 0, payload.Length);
         Console.WriteLine($"RPCMinion: Got data: {gotData}");
         OnToken?.Invoke(this, StartToken.FromString(gotData)); //Invoke method and return.
         return(Encoding.UTF8.GetBytes(serverResponse));
     });
 }
示例#7
0
        public void RPC_MasterCallsSlave_Exception()
        {
            ipcMaster = new RpcBuffer(ipcName);
            ipcSlave  = new RpcBuffer(ipcName, async(msgId, payload) =>
            {
                throw new Exception("test exception");
            });

            var result = ipcMaster.RemoteRequest(null);

            Assert.IsFalse(result.Success);
        }
示例#8
0
        public void RPC_SlaveCallsMasterAfterClosed_Exception()
        {
            ipcMaster = new RpcBuffer(ipcName, async(msgId, payload) =>
            {
            });

            ipcSlave = new RpcBuffer(ipcName);

            ipcSlave.RemoteRequest(null);

            ipcMaster.Dispose();

            Assert.ThrowsException <InvalidOperationException>(() => ipcSlave.RemoteRequest(null));
        }
示例#9
0
        public void RPC_MasterCallsSlave()
        {
            ipcMaster = new RpcBuffer(ipcName);
            ipcSlave  = new RpcBuffer(ipcName, (msgId, payload) =>
            {
                Assert.IsTrue(payload != null);
                Assert.IsTrue(payload.Length == 2);
                // Add the two bytes together
                return(BitConverter.GetBytes((payload[0] + payload[1])));
            });

            var result = ipcMaster.RemoteRequest(new byte[] { 123, 10 });

            Assert.IsTrue(result.Success);
            Assert.AreEqual(123 + 10, BitConverter.ToInt32(result.Data, 0));
        }
示例#10
0
        public void RPC_Bidirectional_Nested()
        {
            ipcMaster = new RpcBuffer(ipcName, async(msgId, payload) =>
            {
                // Ask slave to multiply the two bytes
                return((await ipcMaster.RemoteRequestAsync(new byte[] { 3, 3 }).ConfigureAwait(false)).Data);
            });
            ipcSlave = new RpcBuffer(ipcName, (msgId, payload) =>
            {
                return(new byte[] { (byte)(payload[0] * payload[1]) });
            });

            // Send request to master from slave
            var result = ipcSlave.RemoteRequest(null, 500);

            Assert.IsTrue(result.Success);
            Assert.AreEqual((3 * 3), result.Data[0]);
        }
        public IndexedZiPatchIndexRemoteInstaller(string workerExecutablePath, bool asAdmin)
        {
            var rpcChannelName = "RemoteZiPatchIndexInstaller" + Guid.NewGuid().ToString();

            this.subprocessBuffer = new RpcBuffer(rpcChannelName, RpcResponseHandler);

            if (workerExecutablePath != null)
            {
                this.workerProcess = new();
                this.workerProcess.StartInfo.FileName        = workerExecutablePath;
                this.workerProcess.StartInfo.UseShellExecute = true;
                this.workerProcess.StartInfo.Verb            = asAdmin ? "runas" : "open";
                this.workerProcess.StartInfo.Arguments       = $"index-rpc {Process.GetCurrentProcess().Id} {rpcChannelName}";
                this.workerProcess.Start();
            }
            else
            {
                this.workerProcess = null;
                Task.Run(() => new WorkerSubprocessBody(Process.GetCurrentProcess().Id, rpcChannelName).RunToDisposeSelf());
            }
        }
示例#12
0
 public SharedMemoryRpc(string channelName)
 {
     this.rpcBuffer = new RpcBuffer(channelName, RemoteCallHandler);
 }
示例#13
0
        static void Main(string[] args)
        {
            long completed = 0;
            long count     = 0;

            byte[][] dataList;
            int      loopCount      = 2000;
            int      bufSize        = 1024 * 500;
            int      bufferCapacity = bufSize + 64; // buf size + enough room for protocol header
            int      threadCount    = 1;
            int      dataListCount  = 256;

            // Generate random data to be written
            Random random = new Random();

            dataList = new byte[dataListCount][];
            for (var j = 0; j < dataListCount; j++)
            {
                var data = new byte[bufSize];
                random.NextBytes(data);
                dataList[j] = data;
            }

            Console.WriteLine($"Thread count: {threadCount}");
            Console.WriteLine($"Buffer size: {bufferCapacity}");
            Console.WriteLine($"Message size: {bufSize}");

            Console.WriteLine("Running...");

            Stopwatch watch = Stopwatch.StartNew();

            for (var i = 0; i < threadCount; i++)
            {
                new Task(async() =>
                {
                    RpcBuffer ipcMaster = null;
                    RpcBuffer ipcSlave  = null;
                    var name            = $"MasterSlaveTest{Guid.NewGuid()}";
                    ipcMaster           = new RpcBuffer(name, bufferCapacity: bufferCapacity);
                    ipcSlave            = new RpcBuffer(name, (msgId, payload) =>
                    {
                        Interlocked.Increment(ref count);
                        return((byte[])null);
                        //return new byte[] { (byte)(payload[0] * payload[1]) };
                    });
                    var rnd       = new Random();
                    var watchLine = Stopwatch.StartNew();
                    for (var j = 0; j < loopCount; j++)
                    {
                        var result = await ipcMaster.RemoteRequestAsync(dataList[rnd.Next(0, dataList.Length)]);
                        if (!result.Success)
                        {
                            Console.WriteLine("Failed");
                            return;
                        }
                    }
                    Interlocked.Increment(ref completed);
                }).Start();
            }

            while (Interlocked.Read(ref completed) < threadCount)
            {
                Thread.Sleep(0);
            }

            watch.Stop();
            Console.WriteLine($"{count} in {watch.Elapsed}, {(int)(count / watch.Elapsed.TotalSeconds)} requests / sec");

            Console.ReadLine();
        }