Esempio n. 1
0
        private async Task ProcessEagerSyncRequest(Rpc rpc, EagerSyncRequest cmd)
        {
            logger.Debug("EagerSyncRequest {EagerSyncRequest}", new
            {
                cmd.FromId,
                Events = cmd.Events.Length
            });

            var success = true;

            Exception respErr;

            using (await coreLock.LockAsync())
            {
                respErr = await Sync(cmd.Events);
            }

            if (respErr != null)
            {
                logger.Error("Sync() {error}", respErr);
                success = false;
            }

            var resp = new EagerSyncResponse
            {
                FromId  = Id,
                Success = success
            };

            await rpc.RespondAsync(resp, respErr != null?new NetError(resp.FromId.ToString(), respErr) : null);
        }
Esempio n. 2
0
        private void ProcessEagerSyncRequest(Rpc rpc, EagerSyncRequest cmd)
        {
            logger.Debug("EagerSyncRequest {EagerSyncRequest}", new
            {
                cmd.FromId,
                Events = cmd.Events.Length
            });

            var success = true;

            Exception respErr;

            lock (_operationLock)
            {
                respErr = Sync(cmd.Events).Result;
            }

            if (respErr != null)
            {
                logger.Error("Sync() {error}", respErr);
                success = false;
            }

            var resp = new EagerSyncResponse
            {
                FromId  = Id,
                Success = success
            };

            rpc
            .RespondAsync(resp, respErr != null
                                        ? new NetError(resp.FromId.ToString(), respErr)
                                        : null)
            .Wait();
        }
Esempio n. 3
0
        private async Task <(EagerSyncResponse resp, Exception err)> RequestEagerSync(string target, WireEvent[] events)
        {
            var args = new EagerSyncRequest
            {
                FromId = Id,
                Events = events
            };

            var(resp, err) = await Trans.EagerSync(target, args);

            return(resp, err);
        }
Esempio n. 4
0
        public async Task TestProcessEagerSync()
        {
            var(keys, peers, pmap) = InitPeers(2);

            var config = Config.TestConfig();

            //Start two nodes

            var router = new InMemRouter();

            var id0        = pmap[peers[0].PubKeyHex];
            var peer0Trans = await router.Register(peers[0].NetAddr);

            var node0 = new Node(config, id0, keys[0], peers, new InmemStore(pmap, config.CacheSize, logger), peer0Trans, new InMemAppProxy(id0, logger), logger);
            await node0.Init(false);

            await node0.StartAsync(false);

            var peer1Trans = await router.Register(peers[1].NetAddr);

            var id1   = pmap[peers[1].PubKeyHex];
            var node1 = new Node(config, id1, keys[1], peers, new InmemStore(pmap, config.CacheSize, logger), peer1Trans, new InMemAppProxy(id1, logger), logger);
            await node1.Init(false);

            await node1.StartAsync(false);

            //Manually prepare EagerSyncRequest and expected EagerSyncResponse

            var node1Known = await node1.Controller.KnownEvents();

            Event[]   unknown;
            Exception err;

            (unknown, err) = await node0.Controller.EventDiff(node1Known);

            Assert.Null(err);

            WireEvent[] unknownWire;
            (unknownWire, err) = node0.Controller.ToWire(unknown);
            Assert.Null(err);

            var args = new EagerSyncRequest
            {
                FromId = node0.Id,
                Events = unknownWire
            };

            var expectedResp = new EagerSyncResponse
            {
                FromId  = node1.Id,
                Success = true
            };

            //Make actual EagerSyncRequest and check EagerSyncResponse

            EagerSyncResponse resp;

            (resp, err) = await peer0Trans.EagerSync(peers[1].NetAddr, args);

            Assert.Null(err);

            // Verify the response
            Assert.Equal(expectedResp.Success, resp.Success);

            // shutdown nodes
            node0.Shutdown();
            node1.Shutdown();
        }
Esempio n. 5
0
        public async Task <(EagerSyncResponse resp, NetError err)> EagerSync(string target, EagerSyncRequest args)
        {
            var(rpcResp, err) = await MakeRpc(target, args, Timeout);

            if (err != null)
            {
                return(null, err);
            }

            var syncResp = (EagerSyncResponse)rpcResp.Response;

            return(syncResp, null);
        }
Esempio n. 6
0
 public Task <(EagerSyncResponse resp, NetError err)> EagerSync(string target, EagerSyncRequest args)
 {
     throw new NotImplementedException();
 }