Example #1
0
        public async Task Setup()
        {
            var echoProps = Props.FromFunc(ctx => {
                if (ctx.Sender is not null)
                {
                    ctx.Respond(ctx.Message !);
                }
                return(Task.CompletedTask);
            }
                                           );

            if (RequestDeduplication)
            {
                echoProps = echoProps.WithClusterRequestDeduplication(TimeSpan.FromSeconds(30));
            }

            var echoKind = new ClusterKind(Kind, echoProps);

            if (LocalAffinity)
            {
                echoKind.WithLocalAffinityRelocationStrategy();
            }

            var sys = new ActorSystem(new ActorSystemConfig())
                      .WithRemote(GrpcNetRemoteConfig.BindToLocalhost(9090))
                      .WithCluster(ClusterConfig().WithClusterKind(echoKind));

            _cluster = sys.Cluster();
            await _cluster.StartMemberAsync();

            _id = ClusterIdentity.Create("1", Kind);
            await _cluster.RequestAsync <int>(_id.Identity, _id.Kind, 1, CancellationToken.None);
        }
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// A helper method for ScrVerse cluster tests-
		/// Verifies the given cluster items. (The items could be from Current or Revsion.)
		/// </summary>
		/// <param name="expectedItems">a ScrVerse, or a List of ScrVerses, which we expect the
		/// given cluster items to represent.
		/// A single object indicates we expect one item in clusterItems,
		/// a List indicates we expect multiple items,
		/// a null indicates that we expect zero items.</param>
		/// <param name="clusterItems">The List of OverlapInfo cluster items</param>
		/// <param name="kindOfCluster">The kind of cluster.</param>
		/// ------------------------------------------------------------------------------------
		private void VerifyScrVerseClusterItems(object expectedItems, List<OverlapInfo> clusterItems,
			ClusterKind kindOfCluster)
		{
			if (expectedItems == null)
			{
				Assert.AreEqual(0, clusterItems.Count);
			}
			else if (expectedItems is List<ScrVerse>)
			{
				List<ScrVerse> expectedList = (List<ScrVerse>)expectedItems; //make local var with type info, to reduce code clutter
				Assert.AreEqual(expectedList.Count, clusterItems.Count);
				for (int i = 0; i < expectedList.Count; i++)
				{
					VerifyClusterItem(expectedList[i], clusterItems[i]);
				}
			}
			else
			{	// single object is expected
				Assert.AreEqual(1, clusterItems.Count);
				Assert.IsTrue(expectedItems is ScrVerse, "expected item should be of type ScrVerse");
				VerifyClusterItem(expectedItems, clusterItems[0]);
			}
		}
Example #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// A helper method for section cluster tests-
		/// Verifies the given cluster items. (The items could be from Current or Revsion.)
		/// </summary>
		/// <param name="expectedItems">a CmObject (IScrSection or IScrTxtPara), or a List of
		/// such items, which we expect the given cluster items to represent.
		/// A single object indicates we expect one item in clusterItems,
		/// a List indicates we expect multiple items,
		/// a null indicates that we expect zero items.</param>
		/// <param name="clusterItems">The List of OverlapInfo cluster items</param>
		/// <param name="kindOfCluster">The kind of cluster.</param>
		/// ------------------------------------------------------------------------------------
		private void VerifySectionClusterItems(object expectedItems, List<OverlapInfo> clusterItems,
			ClusterKind kindOfCluster)
		{
			if (expectedItems == null)
			{
				Assert.AreEqual(0, clusterItems.Count);
			}
			else if (expectedItems is List<IScrSection>)
			{
				List<IScrSection> expectedList = (List<IScrSection>)expectedItems; //make local var with type info, to reduce code clutter
				Assert.AreEqual(expectedList.Count, clusterItems.Count);
				for (int i = 0; i < expectedList.Count; i++)
				{
					VerifyClusterItem(expectedList[i], clusterItems[i]);
				}
			}
			else if (expectedItems is List<IScrTxtPara>)
			{
				List<IScrTxtPara> expectedList = (List<IScrTxtPara>)expectedItems; //make local var with type info, to reduce code clutter
				Assert.AreEqual(expectedList.Count, clusterItems.Count);
				for (int i = 0; i < expectedList.Count; i++)
				{
					VerifyClusterItem(expectedList[i], clusterItems[i]);
				}
			}
			else
			{	// single object is expected
				Assert.AreEqual(1, clusterItems.Count);
				switch (kindOfCluster)
				{
					case ClusterKind.ScrSection:
						Assert.IsTrue(expectedItems is IScrSection || expectedItems is IScrTxtPara,
							"expected item should be of type IScrSection or IScrTxtPara");
						break;
					case ClusterKind.ScrVerse:
						Assert.IsTrue(expectedItems is ScrVerse,
							"expected item should be of type ScrVerse");
						break;
				}
				VerifyClusterItem(expectedItems, clusterItems[0]);
			}
		}
Example #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Verifies expected characteristics of any kind of cluster.
		/// </summary>
		/// <param name="cluster">The cluster.</param>
		/// <param name="refMin">The reference min.</param>
		/// <param name="refMax">The reference max.</param>
		/// <param name="type">The cluster type.</param>
		/// <param name="expectedItemsCurr">The expected items in the Current.</param>
		/// <param name="expectedItemsRev">The expected items in the Revision.</param>
		/// <param name="indexToInsertAtInOther">The index to insert at in other.</param>
		/// <param name="kindOfCluster">The kind of cluster.</param>
		/// ------------------------------------------------------------------------------------
		private void VerifyCluster(Cluster cluster, int refMin, int refMax, ClusterType type,
			object expectedItemsCurr, object expectedItemsRev, int indexToInsertAtInOther,
			ClusterKind kindOfCluster)
		{
			// verify the basics
			Assert.AreEqual(refMin, cluster.verseRefMin);
			Assert.AreEqual(refMax, cluster.verseRefMax);
			Assert.AreEqual(type, cluster.clusterType);

			// verify the indexToInsertAtInOther
			Assert.AreEqual(indexToInsertAtInOther, cluster.indexToInsertAtInOther);

			// now verify the cluster's items
			switch (kindOfCluster)
			{
				case ClusterKind.ScrSection:
					VerifySectionClusterItems(expectedItemsCurr, cluster.itemsCurr, kindOfCluster);
					VerifySectionClusterItems(expectedItemsRev, cluster.itemsRev, kindOfCluster);
					break;
				case ClusterKind.ScrVerse:
					VerifyScrVerseClusterItems(expectedItemsCurr, cluster.itemsCurr, kindOfCluster);
					VerifyScrVerseClusterItems(expectedItemsRev, cluster.itemsRev, kindOfCluster);
					break;
			}
		}
Example #5
0
 public static ClusterKind WithLocalAffinityRelocationStrategy(this ClusterKind clusterKind, LocalAffinityOptions?options = null)
 => clusterKind with