public void SubscribeToUpdates() { var store = Utils.CreateStore <InMemorySettings>(dataCenter: DataCenter.West); InMemorySettings settings = null; var callbackCount = 0; store.SubscribeToSettingsForGlobalApp((ex, settingsObj, storeObj) => { if (ex != null) { throw ex; } Assert.AreSame(store, storeObj); settings = settingsObj; callbackCount++; }); Assert.AreEqual(1, callbackCount); Assert.IsNotNull(settings); Assert.AreEqual(NFigStore.INITIAL_COMMIT, settings.Commit); store.SetOverride("Nested.Integer", "32", DataCenter.Any, USER_A); Assert.AreEqual(2, callbackCount); Assert.IsNotNull(settings.Commit); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var log = new InMemoryLog(); var fsm = new InMemoryStateMachine(); var settings = new InMemorySettings(1000, 3500, 50, 5000); var _peers = new List <IPeer>(); var peer1 = new NodePeer(); _peers.Add(new NodePeer() { }); var peersProvider = new InMemoryPeersProvider(_peers); var node = new Node(fsm, log, settings, peersProvider, loggerFactory); node.Start(new NodeId("gsw" + DateTime.Now.ToString("HHmmssfff"))); app.UseMvc(); }
public RequestVoteTests() { _rules = new Rules(); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _node = new NothingNode(); }
public RequestVoteTests() { _loggerFactory = new Mock <ILoggerFactory>(); _rules = new Rules(_loggerFactory.Object, new NodeId(default(string))); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _node = new NothingNode(); }
public AllServersApplyToStateMachineTests() { _rules = new Rules(); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _peers = new List <IPeer>(); _log = new InMemoryLog(); _fsm = new Rafty.FiniteStateMachine.InMemoryStateMachine(); _node = new NothingNode(); }
public AllServersConvertToFollowerTests() { _rules = new Rules(); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _fsm = new InMemoryStateMachine(); _node = new NothingNode(); }
public AppendEntriesTests() { _rules = new Rules(); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _fsm = new InMemoryStateMachine(); _node = new NothingNode(); }
public FollowerTests() { _rules = new Rules(); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _fsm = new InMemoryStateMachine(); _peersProvider = new InMemoryPeersProvider(_peers); _currentState = new CurrentState(Guid.NewGuid().ToString(), 0, default(string), -1, -1, default(string)); }
public CandidateTests() { _rules = new Rules(); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _fsm = new InMemoryStateMachine(); _id = Guid.NewGuid().ToString(); _node = new NothingNode(); _currentState = new CurrentState(_id, 0, default(string), 0, 0, default(string)); }
public IOcelotAdministrationBuilder AddRafty() { var settings = new InMemorySettings(4000, 5000, 100, 5000); _services.AddSingleton <ILog, SqlLiteLog>(); _services.AddSingleton <IFiniteStateMachine, OcelotFiniteStateMachine>(); _services.AddSingleton <ISettings>(settings); _services.AddSingleton <IPeersProvider, FilePeersProvider>(); _services.AddSingleton <INode, Node>(); _services.Configure <FilePeers>(_configurationRoot); return(this); }
public void ConfigureServices(IServiceCollection services) { var settings = new InMemorySettings(4000, 6000, 500, 10000); services.AddSingleton <ILog, SqlLiteLog>(); services.AddSingleton <IFiniteStateMachine, FileFsm>(); services.AddSingleton <ISettings>(settings); services.AddSingleton <IPeersProvider, FilePeersProvider>(); services.AddSingleton <INode, Node>(); services.Configure <FilePeers>(Configuration); services.AddLogging(); }
static void Main(string[] args) { var log = new InMemoryLog(); var fsm = new InMemoryStateMachine(); var settings = new InMemorySettings(1000, 3500, 50, 5000); var _peers = new List <IPeer>(); var peersProvider = new InMemoryPeersProvider(_peers); var node = new Node(fsm, log, settings, peersProvider, null); node.Start(new NodeId("gsw")); }
public static IOcelotAdministrationBuilder AddRafty(this IOcelotAdministrationBuilder builder) { var settings = new InMemorySettings(4000, 6000, 100, 10000); builder.Services.RemoveAll <IFileConfigurationSetter>(); builder.Services.AddSingleton <IFileConfigurationSetter, RaftyFileConfigurationSetter>(); builder.Services.AddSingleton <ILog, SqlLiteLog>(); builder.Services.AddSingleton <IFiniteStateMachine, OcelotFiniteStateMachine>(); builder.Services.AddSingleton <ISettings>(settings); builder.Services.AddSingleton <IPeersProvider, FilePeersProvider>(); builder.Services.AddSingleton <INode, Node>(); builder.Services.Configure <FilePeers>(builder.ConfigurationRoot); return(builder); }
public AllServersConvertToFollowerTests() { _loggerFactory = new Mock <ILoggerFactory>(); var logger = new Mock <ILogger>(); _loggerFactory.Setup(x => x.CreateLogger(It.IsAny <string>())).Returns(logger.Object); _rules = new Rules(_loggerFactory.Object, new NodeId(default(string))); _settings = new InMemorySettingsBuilder().Build(); _random = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _fsm = new InMemoryStateMachine(); _node = new NothingNode(); }
public LeaderTests() { _logger = new Mock <ILogger>(); _loggerFactory = new Mock <ILoggerFactory>(); _loggerFactory.Setup(x => x.CreateLogger(It.IsAny <string>())).Returns(_logger.Object); _rules = new Rules(_loggerFactory.Object, new NodeId(default(string))); _settings = new InMemorySettingsBuilder().Build(); _delay = new RandomDelay(); _log = new InMemoryLog(); _peers = new List <IPeer>(); _fsm = new InMemoryStateMachine(); _id = Guid.NewGuid().ToString(); _currentState = new CurrentState(_id, 0, default(string), 0, 0, default(string)); _node = new NothingNode(); }
public void Get() { ISettings settings = new InMemorySettings(); Assert.That(settings.HasKey("int"), Is.EqualTo(false)); Assert.That(settings.GetInt("int"), Is.EqualTo(0)); Assert.That(settings.GetInt("int", 42), Is.EqualTo(42)); Assert.That(settings.GetBool("bool"), Is.EqualTo(false)); Assert.That(settings.GetBool("bool", true), Is.EqualTo(true)); Assert.That(settings.GetFloat("float"), Is.EqualTo(0.0f)); Assert.That(settings.GetFloat("float", 3.14f), Is.EqualTo(3.14f)); Assert.That(settings.GetString("string"), Is.EqualTo("")); Assert.That(settings.GetString("string", "nada"), Is.EqualTo("nada")); Assert.That(settings.Keys, Is.EqualTo(new List <string>())); }
public async Task ShouldTimeoutAfterXSecondsIfCannotReplicateCommandAndRollbackIndexes() { _peers = new List <IPeer>(); for (var i = 0; i < 3; i++) { _peers.Add(new FakePeer(false, false, false)); } _peers.Add(new FakePeer(true, true, true)); _currentState = new CurrentState(_id, 1, default(string), 0, 0, default(string)); _settings = new InMemorySettingsBuilder().WithCommandTimeout(1).Build(); var leader = new Leader(_currentState, _fsm, (s) => _peers, _log, _node, _settings, _rules, _loggerFactory.Object); var command = new FakeCommand(); var response = await leader.Accept(command); var error = (ErrorResponse <FakeCommand>)response; error.Error.ShouldBe("Unable to replicate command to peers due to timeout."); bool TestPeerStates(List <PeerState> peerState) { var passed = 0; peerState.ForEach(pS => { if (pS.MatchIndex.IndexOfHighestKnownReplicatedLog == 0) { passed++; } if (pS.NextIndex.NextLogIndexToSendToPeer == 1) { passed++; } }); return(passed == peerState.Count * 2); } var result = WaitFor(1000).Until(() => TestPeerStates(leader.PeerStates)); _log.Count().Result.ShouldBe(0); result.ShouldBeTrue(); }
private void AddNewServers(int count) { for (int i = 0; i < count; i++) { var peer = new NodePeer(); _peers.Add(peer); var log = new InMemoryLog(); var fsm = new InMemoryStateMachine(); var set = new InMemorySettings(1000, 3500, 50, 5000); var settings = new InMemorySettingsBuilder().WithMinTimeout(1000).WithMaxTimeout(3500).WithHeartbeatTimeout(50).Build(); var peersProvider = new InMemoryPeersProvider(_peers); var node = new Node(fsm, log, settings, peersProvider); var server = new Server(log, fsm, node); peer.SetNode(server.Node); var nextIndex = _servers.Count; _servers.TryAdd(nextIndex, server); node.Start(Guid.NewGuid().ToString()); } }
private static void DownloadPackages(string packagesDirectory, List <string> sources) { var settings = new InMemorySettings(); var nuGetSettings = new NuGetSettings(settings); nuGetSettings.GlobalPackagesFolder = packagesDirectory; var packageRangeDownloader = new PackageRangeDownloader(nuGetSettings); var alignedVersionDownloader = new AlignedVersionsDownloader(packageRangeDownloader); using (var sourceCacheContext = new SourceCacheContext()) { var downloadTask = DownloadAsync( sources, alignedVersionDownloader, sourceCacheContext, new ConsoleLogger()); downloadTask.Wait(); } }
static void Main(string[] args) { var settings = new InMemorySettings { BitRate = BitRate.Extreme, MillisecondsToCheckForTrackChanges = 10, RecorderDeviceName = "Realtek High Definition Audio", OutputDirectory = Path.Combine(".", "Music"), SkipExistingSongs = true }; var recordingService = new AudioRecordingService(settings); var spotifyService = new SpotifyService(settings); var writer = new SongWriter(settings); IAudioRecorder currentRecorder = null; spotifyService.GetSong().Subscribe(song => { if (currentRecorder != null) { System.Console.WriteLine($"Song {currentRecorder.Song.Title} finished."); StopRecording(currentRecorder, writer); } if (song != null) { System.Console.WriteLine($"Recording song {song.Title}"); currentRecorder = recordingService.StartRecording(song); } else { System.Console.WriteLine("Currently no song is playing."); currentRecorder = null; } }); System.Console.ReadLine(); }
/// <summary> /// Test Set*() methods by fetching stored results. /// </summary> public void Set() { ISettings settings = new InMemorySettings(); Assert.That(settings.HasKey("an_int"), Is.EqualTo(false)); Assert.That(settings.GetInt("an_int"), Is.EqualTo(0)); settings.SetInt("an_int", 42); Assert.That(settings.HasKey("an_int"), Is.EqualTo(true)); Assert.That(settings.GetInt("an_int"), Is.EqualTo(42)); Assert.That(settings.GetInt("an_int", 21), Is.EqualTo(42)); Assert.That(settings.HasKey("a_bool"), Is.EqualTo(false)); Assert.That(settings.GetBool("a_bool"), Is.EqualTo(false)); settings.SetBool("a_bool", true); Assert.That(settings.HasKey("a_bool"), Is.EqualTo(true)); Assert.That(settings.GetBool("a_bool"), Is.EqualTo(true)); Assert.That(settings.GetBool("a_bool", false), Is.EqualTo(true)); Assert.That(settings.HasKey("a_float"), Is.EqualTo(false)); Assert.That(settings.GetFloat("a_float"), Is.EqualTo(0.0f)); settings.SetFloat("a_float", 3.14f); Assert.That(settings.HasKey("a_float"), Is.EqualTo(true)); Assert.That(settings.GetFloat("a_float"), Is.EqualTo(3.14f)); Assert.That(settings.GetFloat("a_float", 0.707f), Is.EqualTo(3.14f)); Assert.That(settings.HasKey("a_string"), Is.EqualTo(false)); Assert.That(settings.GetString("a_string"), Is.EqualTo("")); settings.SetString("a_string", "nada"); Assert.That(settings.HasKey("a_string"), Is.EqualTo(true)); Assert.That(settings.GetString("a_string"), Is.EqualTo("nada")); Assert.That(settings.GetString("a_string", "casa"), Is.EqualTo("nada")); Assert.That(new HashSet <string>(settings.Keys), Is.EqualTo(new HashSet <string> { "an_int", "a_bool", "a_float", "a_string" })); }
public void Construct() { ISettings settings = new InMemorySettings(); Assert.That(settings.Keys, Is.EqualTo(new List <string>())); }
public void ConfigureServices(IServiceCollection services) { services.AddSingleton(serviceProvider => { var hostingEnvironment = serviceProvider.GetService <IHostingEnvironment>(); var settings = new InMemorySettings(); var nuGetSettings = new NuGetSettings(settings); nuGetSettings.GlobalPackagesFolder = Path.Combine(hostingEnvironment.ContentRootPath, "packages"); return(nuGetSettings); }); services.AddLogging(builder => { builder.AddConsole(); builder.AddDebug(); }); services.AddApplicationInsightsTelemetry(); services.AddTransient <IAlignedVersionsDownloader, AlignedVersionsDownloader>(); services.AddTransient <IAssemblyLoader, AssemblyLoader>(); services.AddTransient <IFrameworkEnumerator <Framework>, FrameworkEnumerator>(); services.AddTransient <IFrameworkList, FrameworkList <Framework> >(); services.AddTransient <IPackageLoader, PackageLoader>(); services.AddTransient <IPackageRangeDownloader, PackageRangeDownloader>(); services.AddSingleton <IToolsFactory, ToolsFactory>(); try { // Try to construct the reflection-based tools factory. var serviceProvider = services.BuildServiceProvider(); var toolsFactory = serviceProvider.GetRequiredService <IToolsFactory>(); var versions = toolsFactory.GetAvailableVersionsAsync(CancellationToken.None).Result; if (!versions.Any()) { throw new InvalidOperationException("At least one version is required."); } } catch { // Fallback to using the NuGet version directly referenced by this project. var serviceDescriptor = services.First(x => x.ImplementationType == typeof(ToolsFactory)); services.Remove(serviceDescriptor); services.AddTransient <IFrameworkLogic <Framework>, FrameworkLogic>(); services.AddTransient <IVersionLogic <Version>, VersionLogic>(); services.AddTransient <IVersionRangeLogic <Version, VersionRange>, VersionRangeLogic>(); var clientVersion = NuGet.Versioning.NuGetVersion.Parse(ClientVersionUtility.GetNuGetAssemblyVersion()).ToNormalizedString(); services.AddTransient <IToolsService>(serviceProvider => { return(new ToolsService <Framework, Version, VersionRange>( clientVersion, serviceProvider.GetRequiredService <IFrameworkLogic <Framework> >(), serviceProvider.GetRequiredService <IVersionLogic <Version> >(), serviceProvider.GetRequiredService <IVersionRangeLogic <Version, VersionRange> >())); }); services.AddTransient <IFrameworkPrecedenceService>(serviceProvider => { return(new FrameworkPrecedenceService <Framework>( clientVersion, serviceProvider.GetRequiredService <IFrameworkList>(), serviceProvider.GetRequiredService <IFrameworkLogic <Framework> >())); }); services.AddSingleton <IToolsFactory, SingletonToolsFactory>(); } services.AddMvc(); }