public void TestAffinityRun() { const string cacheName = DefaultCacheName; // Test keys for non-client nodes var nodes = new[] { _grid1, _grid2 }.Select(x => x.GetCluster().GetLocalNode()); var aff = _grid1.GetAffinity(cacheName); foreach (var node in nodes) { var primaryKey = TestUtils.GetPrimaryKey(_grid1, cacheName, node); var affinityKey = aff.GetAffinityKey <int, int>(primaryKey); var computeAction = new ComputeAction { ReservedPartition = aff.GetPartition(primaryKey), CacheNames = new[] { cacheName } }; _grid1.GetCompute().AffinityRun(cacheName, affinityKey, computeAction); Assert.AreEqual(node.Id, ComputeAction.LastNodeId); _grid1.GetCompute().AffinityRunAsync(cacheName, affinityKey, computeAction).Wait(); Assert.AreEqual(node.Id, ComputeAction.LastNodeId); } }
public void TestRunAction() { var id = Guid.NewGuid(); _grid1.GetCompute().Run(new ComputeAction(id)); Assert.AreEqual(1, ComputeAction.InvokeCount(id)); id = Guid.NewGuid(); _grid1.GetCompute().RunAsync(new ComputeAction(id)).Wait(); Assert.AreEqual(1, ComputeAction.InvokeCount(id)); }
public void TestBroadcastAction() { var id = Guid.NewGuid(); _grid1.GetCompute().Broadcast(new ComputeAction(id)); Assert.AreEqual(2, ComputeAction.InvokeCount(id)); id = Guid.NewGuid(); _grid1.GetCompute().BroadcastAsync(new ComputeAction(id)).Wait(); Assert.AreEqual(2, ComputeAction.InvokeCount(id)); }
public void TestRunActions() { var id = Guid.NewGuid(); _grid1.GetCompute().Run(Enumerable.Range(0, 10).Select(x => new ComputeAction(id))); Assert.AreEqual(10, ComputeAction.InvokeCount(id)); var id2 = Guid.NewGuid(); _grid1.GetCompute().RunAsync(Enumerable.Range(0, 10).Select(x => new ComputeAction(id2))).Wait(); Assert.AreEqual(10, ComputeAction.InvokeCount(id2)); }
public void TestAffinityRunWithPartition([Values(true, false)] bool local, [Values(true, false)] bool multiCache, [Values(true, false)] bool async) { var cacheNames = new List <string> { DefaultCacheName }; if (multiCache) { var cache2 = _grid1.CreateCache <int, int>(TestUtils.TestName); cacheNames.Add(cache2.Name); } var node = local ? _grid1.GetCluster().GetLocalNode() : _grid2.GetCluster().GetLocalNode(); var aff = _grid1.GetAffinity(cacheNames[0]); // Wait for some partitions to be assigned to the node. TestUtils.WaitForTrueCondition(() => aff.GetPrimaryPartitions(node).Any()); var part = aff.GetPrimaryPartitions(node).First(); var computeAction = new ComputeAction { ReservedPartition = part, CacheNames = cacheNames }; var action = async ? (Action)(() => _grid1.GetCompute().AffinityRunAsync(cacheNames, part, computeAction).Wait()) : () => _grid1.GetCompute().AffinityRun(cacheNames, part, computeAction); // Good case. action(); Assert.AreEqual(node.Id, ComputeAction.LastNodeId); // Exception in user code. computeAction.ShouldThrow = true; var aex = Assert.Throws <AggregateException>(() => action()); var ex = aex.GetBaseException(); StringAssert.StartsWith("Remote job threw user exception", ex.Message); Assert.AreEqual("Error in ComputeAction", ex.GetInnermostException().Message); }