public async Task ProgressiveCancellationTokenCancelCallsInterrupt() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyCancellableOperation myOperation = new MyCancellableOperation("com.myapp.longop"); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); ICancellableLongOpService proxy = callerChannel.RealmProxy.Services.GetCalleeProxyPortable <ICancellableLongOpService>(); CancellationTokenSource tokenSource = new CancellationTokenSource(); MyProgress <int> progress = new MyProgress <int>(x => { }); Task <int> result = proxy.LongOp(10, progress, tokenSource.Token); Assert.That(myOperation.CancellableInvocation.InterruptCalled, Is.False); tokenSource.Cancel(); Assert.That(myOperation.CancellableInvocation.InterruptCalled, Is.True); }
public async Task CancelCallsCalleeCancellationToken() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; CancellableService service = new CancellableService(); await calleeChannel.RealmProxy.Services.RegisterCallee(service); MyCallback callback = new MyCallback(); IWampCancellableInvocationProxy cancellable = callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.cancellable", new object[] { 100 }); Assert.That(service.CancellationToken, Is.Not.Null); Assert.That(service.CancellationToken.IsCancellationRequested, Is.False); cancellable.Cancel(new CancelOptions()); Assert.That(service.CancellationToken.IsCancellationRequested, Is.True); }
private static async Task RawTest(bool hasSessionId, RegisterOptions registerOptions, CallOptions callOptions) { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, registerOptions); MyCallback myCallback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke(myCallback, callOptions, myOperation.Procedure); long?expectedCaller = null; if (hasSessionId) { expectedCaller = dualChannel.CallerSessionId; } if (callOptions.DiscloseMe == false && registerOptions.DiscloseCaller == true) { Assert.That(myCallback.ErrorUri, Is.EqualTo(WampErrors.DiscloseMeNotAllowed)); } else { Assert.That(myOperation.Details.Caller, Is.EqualTo(expectedCaller)); } }
public async Task ProgressiveCallsCalleeProxyProgress() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); ILongOpService proxy = callerChannel.RealmProxy.Services.GetCalleeProxy <ILongOpService>(); List <int> results = new List <int>(); MyProgress <int> progress = new MyProgress <int>(i => results.Add(i)); Task <int> result = proxy.LongOp(10, progress); result.Wait(); CollectionAssert.AreEquivalent(Enumerable.Range(0, 10), results); Assert.That(result.Result, Is.EqualTo(10)); }
public async Task ProgressiveCallsCallerProgress() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; await calleeChannel.RealmProxy.Services.RegisterCallee(new LongOpService()); MyCallback callback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.longop", new object[] { 10 }); callback.Task.Wait(2000); CollectionAssert.AreEquivalent(Enumerable.Range(0, 10), callback.ProgressiveResults); Assert.That(callback.Task.Result, Is.EqualTo(10)); }
public async Task LongKeywordTupleServiceCalleeProxy() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; var registration = await calleeChannel.RealmProxy.RpcCatalog.Register(new LongValueTuplesService.KeywordTupleOperation(), new RegisterOptions()); IWampChannel callerChannel = dualChannel.CallerChannel; ILongValueTuplesServiceProxy proxy = callerChannel.RealmProxy.Services.GetCalleeProxy <ILongValueTuplesServiceProxy>(); string name = "Homer Simpson"; var(item1, item2, item3, item4, item5, item6, item7, item8, length, item9, item10) = proxy.GetLongKeywordTuple(name); Assert.That(item1, Is.EqualTo(name + " " + 0)); Assert.That(item10, Is.EqualTo(name + " " + 9)); Assert.That(length, Is.EqualTo(name.Length)); }
public async Task ProgressiveCallsCallerProgressCancelObservable() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; var service = new LongOpObsService(); await calleeChannel.RealmProxy.Services.RegisterCallee(service); MyCallback callback = new MyCallback(); var invocation = callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.longop", new object[] { 10, false }); Assert.That(service.State, Is.EqualTo(LongOpObsService.EState.Called)); invocation.Cancel(new CancelOptions()); Assert.That(service.State, Is.EqualTo(LongOpObsService.EState.Cancelled)); }
private async Task MethodInfoTest(bool hasSessionId, RegisterOptions registerOptions, CallOptions callOptions) { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyService service = new MyService(); Task registerTask = calleeChannel.RealmProxy.Services.RegisterCallee(service, new CalleeRegistrationInterceptor(registerOptions)); await registerTask; IAddService calleeProxy = callerChannel.RealmProxy.Services.GetCalleeProxyPortable <IAddService>(new CalleeProxyInterceptor(callOptions)); WampException caughtException = null; try { int seven = calleeProxy.Add2(3, 4); } catch (WampException ex) { caughtException = ex; } InvocationDetails details = service.Details; long?expectedCaller = null; if (hasSessionId) { expectedCaller = dualChannel.CallerSessionId; } if (registerOptions.DiscloseCaller == true && callOptions.DiscloseMe == false) { Assert.That(caughtException.ErrorUri, Is.EqualTo(WampErrors.DiscloseMeNotAllowed)); Assert.That(details, Is.EqualTo(null)); } else { Assert.That(details.Caller, Is.EqualTo(expectedCaller)); } }
public async Task ProgressiveCallsCalleeProxyObservableError() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); ILongOpObsService proxy = callerChannel.RealmProxy.Services.GetCalleeProxy <ILongOpObsService>(); Assert.Throws(typeof(WampException), () => proxy.LongOp(9, true).ToEnumerable().Count()); }
public async Task ProgressiveCallsCalleeProxyObservable() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); ILongOpObsService proxy = callerChannel.RealmProxy.Services.GetCalleeProxy <ILongOpObsService>(); IEnumerable <int> results = proxy.LongOp(9, false).ToEnumerable(); // it will emit one more than asked CollectionAssert.AreEquivalent(Enumerable.Range(0, 10), results); }
public async Task LongKeywordTupleServiceCalleeProxy() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; var registration = await calleeChannel.RealmProxy.RpcCatalog.Register(new LongValueTuplesService.KeywordTupleOperation(), new RegisterOptions()); IWampChannel callerChannel = dualChannel.CallerChannel; ILongValueTuplesServiceProxy proxy = callerChannel.RealmProxy.Services.GetCalleeProxyPortable <ILongValueTuplesServiceProxy>(); string name = "Homer Simpson"; //(string item1, string item2, string item3, string item4, string item5, string item6, string item7, string item8, int count, string item9, string item10) = // proxy.GetLongPositionalTuple(name); ValueTuple <string, string, string, string, string, string, string, ValueTuple <string, int, string, string> > expr_3E = proxy.GetLongKeywordTuple(name); string item1 = expr_3E.Item1; string item2 = expr_3E.Item2; string item3 = expr_3E.Item3; string item4 = expr_3E.Item4; string item5 = expr_3E.Item5; string item6 = expr_3E.Item6; string item7 = expr_3E.Item7; string item8 = expr_3E.Rest.Item1; int length = expr_3E.Rest.Item2; string item9 = expr_3E.Rest.Item3; string item10 = expr_3E.Rest.Item4; Assert.That(item1, Is.EqualTo(name + " " + 0)); Assert.That(item10, Is.EqualTo(name + " " + 9)); Assert.That(length, Is.EqualTo(name.Length)); }