private static SiloAddress CreateSiloAddressForTest() { var siloAddress = SiloAddressUtils.NewLocalSiloAddress(Interlocked.Increment(ref generation)); siloAddress.Endpoint.Port = 12345; return(siloAddress); }
public FabricMembershipOracleTests(ITestOutputHelper output) { this.Output = output; this.siloDetails = new MockSiloDetails { Name = Guid.NewGuid().ToString("N"), SiloAddress = SiloAddressUtils.NewLocalSiloAddress(SiloAddress.AllocateNewGeneration()) }; this.resolver = new MockResolver(); var globalConfig = new ClusterConfiguration().Globals; globalConfig.MaxMultiClusterGateways = 2; globalConfig.ClusterId = "MegaGoodCluster"; this.fabricMembershipOptions = new ServiceFabricMembershipOptions(); this.unknownSiloMonitor = new UnknownSiloMonitor( new OptionsWrapper <ServiceFabricMembershipOptions>(this.fabricMembershipOptions), new TestOutputLogger <UnknownSiloMonitor>(this.Output)); this.oracle = new FabricMembershipOracle( this.siloDetails, globalConfig, this.resolver, new NullLogger <FabricMembershipOracle>(), this.unknownSiloMonitor); }
public async Task SiloInstanceTable_Op_CleanDeadSiloInstance() { // Register a silo entry await manager.TryCreateTableVersionEntryAsync(); this.generation = 0; RegisterSiloInstance(); // and mark it as dead await manager.UnregisterSiloInstance(myEntry); // Create new active entries for (int i = 1; i < 5; i++) { this.generation = i; this.siloAddress = SiloAddressUtils.NewLocalSiloAddress(generation); var instance = RegisterSiloInstance(); await manager.ActivateSiloInstance(instance); } await Task.Delay(TimeSpan.FromSeconds(3)); await manager.CleanupDefunctSiloEntries(DateTime.Now - TimeSpan.FromSeconds(1)); var entries = await manager.FindAllSiloEntries(); Assert.Equal(5, entries.Count); Assert.All(entries, e => Assert.NotEqual(SiloInstanceTableTestConstants.INSTANCE_STATUS_DEAD, e.Item1.Status)); }
public void GrainReference_Test1() { Guid guid = Guid.NewGuid(); GrainId regularGrainId = GrainId.GetGrainIdForTesting(guid); GrainReference grainRef = this.environment.InternalGrainFactory.GetGrain(regularGrainId); TestGrainReference(grainRef); grainRef = GrainReference.FromGrainId(regularGrainId, null, "generic"); TestGrainReference(grainRef); GrainId systemTragetGrainId = GrainId.NewSystemTargetGrainIdByTypeCode(2); grainRef = GrainReference.FromGrainId(systemTragetGrainId, null, null, SiloAddressUtils.NewLocalSiloAddress(1)); this.environment.GrainFactory.BindGrainReference(grainRef); TestGrainReference(grainRef); GrainId observerGrainId = GrainId.NewClientId(); grainRef = GrainReference.NewObserverGrainReference(observerGrainId, GuidId.GetNewGuidId(), this.environment.RuntimeClient.GrainReferenceRuntime); this.environment.GrainFactory.BindGrainReference(grainRef); TestGrainReference(grainRef); GrainId geoObserverGrainId = GrainId.NewClientId("clusterid"); grainRef = GrainReference.NewObserverGrainReference(geoObserverGrainId, GuidId.GetNewGuidId(), this.environment.RuntimeClient.GrainReferenceRuntime); this.environment.GrainFactory.BindGrainReference(grainRef); TestGrainReference(grainRef); }
public FabricMembershipOracleTests(ITestOutputHelper output) { this.Output = output; this.siloDetails = new MockSiloDetails { Name = Guid.NewGuid().ToString("N"), SiloAddress = SiloAddressUtils.NewLocalSiloAddress(SiloAddress.AllocateNewGeneration()) }; this.resolver = new MockResolver(); var multiClusterOptions = new MultiClusterOptions { HasMultiClusterNetwork = true, MaxMultiClusterGateways = 2 }; this.fabricClusteringOptions = new ServiceFabricClusteringOptions(); this.unknownSiloMonitor = new UnknownSiloMonitor( new OptionsWrapper <ServiceFabricClusteringOptions>(this.fabricClusteringOptions), new TestOutputLogger <UnknownSiloMonitor>(this.Output)); this.oracle = new FabricMembershipOracle( this.siloDetails, this.resolver, new NullLogger <FabricMembershipOracle>(), this.unknownSiloMonitor, Options.Create(multiClusterOptions)); }
public void SerializationTests_Exception_Orleans() { var activationAddress = ActivationAddress.NewActivationAddress(SiloAddressUtils.NewLocalSiloAddress(12345), GrainId.NewId()); var original = new Catalog.NonExistentActivationException("Some message", activationAddress, false); var output = this.fixture.SerializationManager.RoundTripSerializationForTesting(original); Assert.Equal(original.Message, output.Message); Assert.Equal(original.NonExistentActivation, output.NonExistentActivation); Assert.Equal(original.IsStatelessWorker, output.IsStatelessWorker); }
private Dictionary <SiloAddress, ConsistentRingProvider> CreateServers(int n) { Dictionary <SiloAddress, ConsistentRingProvider> rings = new Dictionary <SiloAddress, ConsistentRingProvider>(); for (int i = 1; i <= n; i++) { SiloAddress addr = SiloAddressUtils.NewLocalSiloAddress(i); rings.Add(addr, new ConsistentRingProvider(addr, NullLoggerFactory.Instance)); } return(rings); }
public void ConsistentRingProvider_Test3() { int NUM_SILOS = 100; double NUM_QUEUES = 10024.0; int NUM_AGENTS = 4; Random random = new Random(); SiloAddress silo1 = SiloAddressUtils.NewLocalSiloAddress(random.Next(100000)); VirtualBucketsRingProvider ring = new VirtualBucketsRingProvider(silo1, NullLoggerFactory.Instance, 50); //ring.logger.SetSeverityLevel(Severity.Warning); for (int i = 1; i <= NUM_SILOS - 1; i++) { ring.SiloStatusChangeNotification(SiloAddressUtils.NewLocalSiloAddress(random.Next(100000)), SiloStatus.Active); } IDictionary <SiloAddress, IRingRangeInternal> siloRanges = ring.GetRanges(); List <Tuple <SiloAddress, IRingRangeInternal> > sortedSiloRanges = siloRanges.Select(kv => new Tuple <SiloAddress, IRingRangeInternal>(kv.Key, kv.Value)).ToList(); sortedSiloRanges.Sort((t1, t2) => t1.Item2.RangePercentage().CompareTo(t2.Item2.RangePercentage())); Dictionary <SiloAddress, List <IRingRangeInternal> > allAgentRanges = new Dictionary <SiloAddress, List <IRingRangeInternal> >(); foreach (var siloRange in siloRanges) { var multiRange = RangeFactory.CreateEquallyDividedMultiRange(siloRange.Value, NUM_AGENTS); List <IRingRangeInternal> agentRanges = new List <IRingRangeInternal>(); for (int i = 0; i < NUM_AGENTS; i++) { IRingRangeInternal agentRange = (IRingRangeInternal)multiRange.GetSubRange(i); agentRanges.Add(agentRange); } allAgentRanges.Add(siloRange.Key, agentRanges); } Dictionary <SiloAddress, List <int> > queueHistogram = GetQueueHistogram(allAgentRanges, (int)NUM_QUEUES); string str = Utils.EnumerableToString(sortedSiloRanges, tuple => String.Format("Silo {0} -> Range {1:0.000}%, {2} queues: {3}", tuple.Item1, tuple.Item2.RangePercentage(), queueHistogram[tuple.Item1].Sum(), Utils.EnumerableToString(queueHistogram[tuple.Item1])), "\n"); output.WriteLine("\n\n*** The whole ring with {0} silos is:\n{1}\n\n", NUM_SILOS, str); output.WriteLine("Total number of queues is: {0}", queueHistogram.Values.Select(list => list.Sum()).Sum()); output.WriteLine("Expected average range per silo is: {0:0.00}%, expected #queues per silo is: {1:0.00}, expected #queues per agent is: {2:0.000}.", 100.0 / NUM_SILOS, NUM_QUEUES / NUM_SILOS, NUM_QUEUES / (NUM_SILOS * NUM_AGENTS)); output.WriteLine("Min #queues per silo is: {0}, Max #queues per silo is: {1}.", queueHistogram.Values.Select(list => list.Sum()).ToList().Min(), queueHistogram.Values.Select(list => list.Sum()).ToList().Max()); }
public void ConsistentRingProvider_Test1() { SiloAddress silo1 = SiloAddressUtils.NewLocalSiloAddress(0); ConsistentRingProvider ring = new ConsistentRingProvider(silo1, NullLoggerFactory.Instance); output.WriteLine("Silo1 range: {0}. The whole ring is: {1}", ring.GetMyRange(), ring.ToString()); ring.AddServer(SiloAddressUtils.NewLocalSiloAddress(1)); output.WriteLine("Silo1 range: {0}. The whole ring is: {1}", ring.GetMyRange(), ring.ToString()); ring.AddServer(SiloAddressUtils.NewLocalSiloAddress(2)); output.WriteLine("Silo1 range: {0}. The whole ring is: {1}", ring.GetMyRange(), ring.ToString()); }
public SiloInstanceTableManagerTests(ITestOutputHelper output, Fixture fixture) { TestUtils.CheckForAzureStorage(); this.output = output; this.clusterId = "test-" + Guid.NewGuid(); generation = SiloAddress.AllocateNewGeneration(); siloAddress = SiloAddressUtils.NewLocalSiloAddress(generation); output.WriteLine("ClusterId={0} Generation={1}", this.clusterId, generation); output.WriteLine("Initializing SiloInstanceManager"); manager = OrleansSiloInstanceManager.GetManager(this.clusterId, TestDefaultConfiguration.DataConnectionString, fixture.LoggerFactory) .WaitForResultWithThrow(SiloInstanceTableTestConstants.Timeout); }
public void ConsistentRingProvider_Test2() { SiloAddress silo1 = SiloAddressUtils.NewLocalSiloAddress(0); VirtualBucketsRingProvider ring = new VirtualBucketsRingProvider(silo1, NullLoggerFactory.Instance, 30); //ring.logger.SetSeverityLevel(Severity.Warning); output.WriteLine("\n\n*** Silo1 range: {0}.\n*** The whole ring with 1 silo is:\n{1}\n\n", ring.GetMyRange(), ring.ToString()); for (int i = 1; i <= 10; i++) { ring.SiloStatusChangeNotification(SiloAddressUtils.NewLocalSiloAddress(i), SiloStatus.Active); output.WriteLine("\n\n*** Silo1 range: {0}.\n*** The whole ring with {1} silos is:\n{2}\n\n", ring.GetMyRange(), i + 1, ring.ToString()); } }
public void SiloAddress_ToFrom_ParsableString() { SiloAddress address1 = SiloAddressUtils.NewLocalSiloAddress(12345); string addressStr1 = address1.ToParsableString(); SiloAddress addressObj1 = SiloAddress.FromParsableString(addressStr1); output.WriteLine("Convert -- From: {0} Got result string: '{1}' object: {2}", address1, addressStr1, addressObj1); Assert.Equal(address1, addressObj1); // SiloAddress equal after To-From-ParsableString //const string addressStr2 = "127.0.0.1-11111-144611139"; const string addressStr2 = "127.0.0.1:11111@144611139"; SiloAddress addressObj2 = SiloAddress.FromParsableString(addressStr2); string addressStr2Out = addressObj2.ToParsableString(); output.WriteLine("Convert -- From: {0} Got result string: '{1}' object: {2}", addressStr2, addressStr2Out, addressObj2); Assert.Equal(addressStr2, addressStr2Out); // SiloAddress equal after From-To-ParsableString }
internal async Task Run_ActivationSched_Test1(TaskScheduler scheduler, bool bounceToThreadPool) { var grainId = LegacyGrainId.GetGrainId(0, Guid.NewGuid()); var silo = new MockSiloDetails { SiloAddress = SiloAddressUtils.NewLocalSiloAddress(23) }; var grain = NonReentrentStressGrainWithoutState.Create(grainId, new GrainRuntime(Options.Create(new ClusterOptions()), silo, null, null, null, null, null, NullLoggerFactory.Instance)); await Task.Factory.StartNew(() => grain.OnActivateAsync(), CancellationToken.None, TaskCreationOptions.None, scheduler).Unwrap(); Task wrapped = null; var wrapperDone = new TaskCompletionSource <bool>(); var wrappedDone = new TaskCompletionSource <bool>(); Task <Task> wrapper = new Task <Task>(() => { this.output.WriteLine("#0 - new Task - SynchronizationContext.Current={0} TaskScheduler.Current={1}", SynchronizationContext.Current, TaskScheduler.Current); Task t1 = grain.Test1(); Action wrappedDoneAction = () => { wrappedDone.SetResult(true); }; if (bounceToThreadPool) { wrapped = t1.ContinueWith(_ => wrappedDoneAction(), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); } else { wrapped = t1.ContinueWith(_ => wrappedDoneAction()); } wrapperDone.SetResult(true); return(wrapped); }); wrapper.Start(scheduler); await wrapper; var timeoutLimit = TimeSpan.FromSeconds(1); try { await wrapperDone.Task.WithTimeout(timeoutLimit); } catch (TimeoutException) { Assert.True(false, "Result did not arrive before timeout " + timeoutLimit); } bool done = wrapperDone.Task.Result; Assert.True(done, "Wrapper Task finished"); Assert.True(wrapper.IsCompleted, "Wrapper Task completed"); //done = wrapped.Wait(TimeSpan.FromSeconds(12)); //Assert.True(done, "Wrapped Task not timeout"); await wrapped; try { await wrappedDone.Task.WithTimeout(timeoutLimit); } catch (TimeoutException) { Assert.True(false, "Result did not arrive before timeout " + timeoutLimit); } done = wrappedDone.Task.Result; Assert.True(done, "Wrapped Task should be finished"); Assert.True(wrapped.IsCompleted, "Wrapped Task completed"); }
protected async Task SqlStatisticsPublisher_ReportMetrics_Silo() { var options = new SqlMembershipOptions() { AdoInvariant = AdoInvariant, ConnectionString = ConnectionString }; IMembershipTable mbr = new SqlMembershipTable(this.environment.Services.GetRequiredService <IGrainReferenceConverter>(), this.environment.Services.GetRequiredService <IOptions <SiloOptions> >(), Options.Create(options), this.loggerFactory.CreateLogger <SqlMembershipTable>()); await mbr.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(1)); StatisticsPublisher.AddConfiguration("statisticsDeployment", true, "statisticsSiloId", SiloAddressUtils.NewLocalSiloAddress(0), new IPEndPoint(IPAddress.Loopback, 12345), "statisticsHostName"); await RunParallel(10, () => StatisticsPublisher.ReportMetrics((ISiloPerformanceMetrics) new DummyPerformanceMetrics())); }