public async Task TimerTest() { await using var serving = await WebSocketHost.ServeAsync(); var tp = Services.GetRequiredService <ITimeService>(); var pub = await Publisher.PublishAsync(_ => tp.GetTimeAsync()); var rep = Replicator.GetOrAdd <DateTime>(pub.Ref); await rep.RequestUpdateAsync().AsAsyncFunc() .Should().CompleteWithinAsync(TimeSpan.FromMinutes(1)); var count = 0; using var state = StateFactory.NewLive <DateTime>( o => o.WithZeroUpdateDelay(), async(_, ct) => await rep.Computed.UseAsync(ct)); state.Updated += s => { Out.WriteLine($"Client: {s.Value}"); count++; }; await TestEx.WhenMet( () => count.Should().BeGreaterThan(2), TimeSpan.FromSeconds(5)); }
static int Main(string[] args) { // TODO: Extract this to configuration var result = log4net.Config.BasicConfigurator.Configure(); string couchdb_host = "http://localhost:5984"; string couchdb_name = "config"; string config_id = null; switch (args.Length) { case 3: config_id = args[2]; goto case 2; case 2: couchdb_name = args[1]; goto case 1; case 1: couchdb_host = args[0]; break; } var cts = new Replicator().Start(couchdb_host, couchdb_name, config_id); Logger.Info("Replicator has started."); SetConsoleCtrlHandler((CtrlType) => { cts.Cancel(); return(true); }, true); cts.Token.WaitHandle.WaitOne(); System.Console.ReadKey(); return(0); }
private static void InitCouchBase() { NetDesktop.Activate(); // Get the database (and create it if it doesn't exist) _database = new Database("db"); // Create replicator to push and pull changes to and from the cloud var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4984/db")); var replConfig = new ReplicatorConfiguration(_database, targetEndpoint); // Add authentication replConfig.Authenticator = new BasicAuthenticator("sync_gateway", "password"); replConfig.ReplicatorType = ReplicatorType.PushAndPull; replConfig.Continuous = true; // Create replicator (make sure to add an instance or static variable // named _Replicator) _Replicator = new Replicator(replConfig); _Replicator.AddChangeListener((sender, args) => { Instance.DataChanged.Invoke(sender, args); _log.Debug($"status={args.Status.Activity}"); _log.Debug($"progress={args.Status.Progress.Completed}/{args.Status.Progress.Total}"); _log.Debug($"error={args.Status.Error}"); if (args.Status.Error != null) { _log.Error($"Error :: {args.Status.Error}"); } }); _Replicator.Start(); }
public void StartReplication() { try { var targetUrlEndpoint = new URLEndpoint(new Uri(_remoteSyncUrl, _databaseName)); var configuration = new ReplicatorConfiguration(Database, targetUrlEndpoint) { ReplicatorType = ReplicatorType.PushAndPull, Continuous = true }; _replicator = new Replicator(configuration); _replicatorListenerToken = _replicator.AddChangeListener(OnReplicatorUpdate); _replicator.Start(); } catch (Exception ex) { // We don't want replication errors to prevent us from // using the app, but we do want to know about them. Console.WriteLine($"Replication Exception - {ex.Message}"); } }
/// <summary> /// Constructor /// </summary> /// <param name="db">The user's database</param> /// <param name="replicator">The user's replicator (already started)</param> /// <param name="username">The user's username</param> public CouchbaseSession(Database db, Replicator replicator, string username) { Database = db; Replicator = replicator; Username = username; _userDocID = new Lazy <string>(GetUserDocID, LazyThreadSafetyMode.None); }
public MainWindow() { InitializeComponent(); log4net.Config.XmlConfigurator.Configure(); Couchbase.Lite.Support.NetDesktop.Activate(); var config = new DatabaseConfiguration() { Directory = AppDomain.CurrentDomain.BaseDirectory }; Database = new Database(DbName, config); var configSync = new ReplicatorConfiguration(Database, new URLEndpoint(SyncGatewayUrl)) { ReplicatorType = ReplicatorType.PushAndPull, Continuous = true }; configSync.Authenticator = new BasicAuthenticator("emonthly", "password"); _replication = new Replicator(configSync); _replication.AddChangeListener((sender, args) => { Console.WriteLine(args.Status.Activity); }); _replication.Start(); }
public override void OnNotified(string channel, string message) { var args = message.Split(new char[] { '|' }, 5); if (args.Length < 3) { Logger.WarnFormat("Message has invalid format [{0}]: {1}", channel, message); return; } Logger.DebugFormat("Message recevied [{0}]: {1}", channel, message); var command = args[1]; var redis_key = args[2]; if (string.Equals("SetDictionary", args[1])) { Replicator.CopyHashValue(this.ReplicationConfig.RedisSourceKey, redis_key, this.ReplicationConfig.CouchTargetDatabase); } else if (string.Equals("RemoveDictionary", args[1])) { Replicator.DeleteCouchDocument(this.ReplicationConfig.CouchTargetDatabase, redis_key); } else { Logger.WarnFormat("Message has unrecognized argument '{0}' [{1}]: {2}", args[1], channel, message); } }
private void Connect() { try { if (_serverInfo == null) { _serverInfo = _serverDal.Get(); } if (_serverInfo == null) { return; } Uri target = new Uri($"ws://{_serverInfo.UrlServer}"); IEndpoint endpoint = new URLEndpoint(target); ReplicatorConfiguration replicationConfig = new ReplicatorConfiguration(_dataBaseGetter.Get(), endpoint) { Continuous = true, ReplicatorType = ReplicatorType.PushAndPull, Authenticator = new BasicAuthenticator(_serverInfo.Login, _serverInfo.Password) }; _replicator = new Replicator(replicationConfig); if (CrossConnectivity.IsSupported && CrossConnectivity.Current.IsConnected) { _replicator.Start(); } _token = _replicator.AddChangeListener(_replicator_StatusChanged); } catch (Exception e) { #if DEBUG #endif } }
private void CheckReplicatorServerCert(bool listenerTls, bool replicatorTls) { var listener = CreateListener(listenerTls); var serverCert = listenerTls ? listener.TlsIdentity.Certs[0] : null; var config = CreateConfig(listener.LocalEndpoint(), ReplicatorType.PushAndPull, true, sourceDb: OtherDb, serverCert: replicatorTls ? serverCert : null); X509Certificate2 receivedServerCert = null; using (var repl = new Replicator(config)) { RunReplicatorServerCert(repl, listenerTls == replicatorTls, serverCert); receivedServerCert = repl.ServerCertificate; } if (listenerTls != replicatorTls) { config = CreateConfig(listener.LocalEndpoint(), ReplicatorType.PushAndPull, true, sourceDb: OtherDb, serverCert: receivedServerCert); using (var repl = new Replicator(config)) { RunReplicatorServerCert(repl, true, serverCert); } } _listener.Stop(); }
private Replicator StartReplication(string username, string password, Database db) { if (String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password)) { throw new InvalidOperationException("User credentials not provided"); } var dbUrl = new Uri(SyncUrl, DbName); Debug.WriteLine( $"PushPull Replicator:Will connect to {SyncUrl}"); var config = new ReplicatorConfiguration(db, new URLEndpoint(dbUrl)) { ReplicatorType = ReplicatorType.PushAndPull, Continuous = true, Authenticator = new BasicAuthenticator(username, password), Channels = new[] { $"channel.{username}" } }; var repl = new Replicator(config); repl.AddChangeListener((sender, args) => { var s = args.Status; Debug.WriteLine( $"PushPull Replicator: {s.Progress.Completed}/{s.Progress.Total}, error {s.Error?.Message ?? "<none>"}, activity = {s.Activity}"); }); repl.Start(); return(repl); }
public async Task BasicTest() { await using var serving = await WebSocketHost.ServeAsync(); var sp = Services.GetRequiredService <ISimplestProvider>(); sp.SetValue(""); var p1 = await Publisher.PublishAsync(_ => sp.GetValueAsync()); p1.Should().NotBeNull(); var r1 = Replicator.GetOrAdd <string>(p1.Ref, true); var r1c = await r1.Computed.UpdateAsync(false); r1c.IsConsistent.Should().BeTrue(); r1c.Value.Should().Be(""); r1.Computed.Should().Be(r1c); sp.SetValue("1"); await Task.Delay(100); r1c.IsConsistent.Should().BeFalse(); r1.Computed.Should().Be(r1c); r1c = await r1c.UpdateAsync(false); r1c.Value.Should().Be("1"); var r1c1 = await r1c.UpdateAsync(false); r1c1.Should().Be(r1c); }
public void TestAuthenticationFailure() { var config = CreateConfig(false, true, false, new URLEndpoint(new Uri("ws://localhost/seekrit"))); _repl = new Replicator(config); RunReplication(config, 401, C4ErrorDomain.WebSocketDomain); }
public void CreateReplicator(string PeerEndpointString) { if (_repl != null) { return; } Uri host = new Uri(PeerEndpointString); var dbUrl = new Uri(host, _db.Name); var replicatorConfig = new ReplicatorConfiguration(_db, new URLEndpoint(dbUrl)); // <1> replicatorConfig.ReplicatorType = ReplicatorType.PushAndPull; replicatorConfig.Continuous = true; if (CoreApp.ListenerTLSMode > 0) { // Explicitly allows self signed certificates. By default, only // CA signed cert is allowed switch (CoreApp.ListenerCertValidationMode) // <2> { case LISTENER_CERT_VALIDATION_MODE.SKIP_VALIDATION: // Use acceptOnlySelfSignedServerCertificate set to true to only accept self signed certs. // There is no cert validation replicatorConfig.AcceptOnlySelfSignedServerCertificate = true; break; case LISTENER_CERT_VALIDATION_MODE.ENABLE_VALIDATION_WITH_CERT_PINNING: // Use acceptOnlySelfSignedServerCertificate set to false to only accept CA signed certs // Self signed certs will fail validation replicatorConfig.AcceptOnlySelfSignedServerCertificate = false; // Enable cert pinning to only allow certs that match pinned cert try { var pinnedCert = LoadSelfSignedCertForListenerFromBundle(); replicatorConfig.PinnedServerCertificate = pinnedCert; } catch (Exception ex) { Debug.WriteLine($"Failed to load server cert to pin. Will proceed without pinning. {ex}"); } break; case LISTENER_CERT_VALIDATION_MODE.ENABLE_VALIDATION: // Use acceptOnlySelfSignedServerCertificate set to false to only accept CA signed certs // Self signed certs will fail validation. There is no cert pinning replicatorConfig.AcceptOnlySelfSignedServerCertificate = false; break; } } if (CoreApp.RequiresUserAuth) { var user = CoreApp.CurrentUser; replicatorConfig.Authenticator = new BasicAuthenticator(user.Username, user.Password); // <3> } _repl = new Replicator(replicatorConfig); // <4> _listenerToken = _repl.AddChangeListener(ReplicationStatusUpdate); }
protected override void OnStart(string[] args) { Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); _logger.Trace("File version: {0}", fileVersionInfo.FileVersion); _logger.Trace("Assembly version: {0}", assembly.GetName().Version); string historianConnection; string pdgtmConnectionString; string settingsConnectionString; try { historianConnection = ConfigurationManager.ConnectionStrings["HistorianConnection"].ConnectionString; pdgtmConnectionString = ConfigurationManager.ConnectionStrings["TeamworkConnection"].ConnectionString; settingsConnectionString = ConfigurationManager.ConnectionStrings["SettingsDb"].ConnectionString; _logger.Trace("Database connection strings loaded successfully"); } catch (Exception ex) { _logger.Fatal("Fail to load connection strings", ex); throw; } try { ISettingsManager settingsManager = new SettingsManager(settingsConnectionString); IPdgtmDbAdapter pdgtmDbAdapter = new PdgtmDbAdapter(pdgtmConnectionString); IHistorianAdapter historianAdapter = new HistorianAdapter(historianConnection); IDatabaseObserver databaseObserver = new DatabaseObserver(historianConnection, pdgtmConnectionString); IReporter reporter = new DbReporter(historianAdapter); IEmulator emulator = new Emulator(reporter); IReplicator replicator = new Replicator(pdgtmDbAdapter, historianAdapter); var wellEmulator = new WellEmulator( emulator, replicator, pdgtmDbAdapter, historianAdapter, settingsManager, databaseObserver); if (_serviceHost != null) { _serviceHost.Close(); _serviceHost = null; } _serviceHost = new ServiceHost(wellEmulator); var behavior = _serviceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>(); behavior.InstanceContextMode = InstanceContextMode.Single; _serviceHost.Open(); _logger.Trace("Service started!"); } catch (Exception ex) { _logger.Fatal("Service failed with fatal error! See stack trace.", ex); throw; } }
public ReplicatorResiliencySpec(ITestOutputHelper helper) : base(SpecConfig, helper) { _sys1 = Sys; _sys3 = ActorSystem.Create(Sys.Name, Sys.Settings.Config); _sys2 = ActorSystem.Create(Sys.Name, Sys.Settings.Config); var settings = ReplicatorSettings.Create(Sys) .WithGossipInterval(TimeSpan.FromSeconds(1.0)) .WithMaxDeltaElements(10) .WithRestartReplicatorOnFailure(true); var props = BackoffSupervisor.Props( Backoff.OnStop( childProps: Replicator.Props(settings), childName: "replicator", minBackoff: TimeSpan.FromSeconds(3), maxBackoff: TimeSpan.FromSeconds(300), randomFactor: 0.2, maxNrOfRetries: -1) .WithFinalStopMessage(m => m is Terminate)) .WithDeploy(Deploy.Local).WithDispatcher(settings.Dispatcher); _replicator1 = _sys1.ActorOf(props, "replicatorSuper"); _replicator2 = _sys2.ActorOf(props, "replicatorSuper"); _replicator3 = _sys3.ActorOf(props, "replicatorSuper"); }
public void TestAuthenticationFailure() { var config = CreateConfig(false, true, false, new URLEndpoint(new Uri("ws://localhost/seekrit"))); _repl = new Replicator(config); RunReplication(config, (int)CouchbaseLiteError.HTTPAuthRequired, CouchbaseLiteErrorType.CouchbaseLite); }
public ReplicatorRow(Replicator replicator) { BackingReplicator = replicator; CollectObjects(); SetupUI(); }
private void GetState() { for (int i = 0; i < NrOfKeys; i++) { Replicator.Tell(Dsl.Get(_stateKeys[i], _readConsistency, i)); } }
/// <summary> /// Returns a dictionary of the function end points that are type compatible /// with any branch of replicated parameters. /// </summary> /// <param name="context"></param> /// <param name="formalParams"></param> /// <param name="replicationInstructions"></param> /// <param name="classTable"></param> /// <param name="runtimeCore"></param> /// <returns></returns> public Dictionary <FunctionEndPoint, int> GetLooseConversionDistances( Runtime.Context context, List <StackValue> formalParams, List <ReplicationInstruction> replicationInstructions, ClassTable classTable, RuntimeCore runtimeCore) { Dictionary <FunctionEndPoint, int> ret = new Dictionary <FunctionEndPoint, int>(); var reducedParams = Replicator.ComputeAllReducedParams(formalParams, replicationInstructions, runtimeCore); foreach (FunctionEndPoint fep in FunctionEndPoints) { foreach (var reducedParam in reducedParams) { int distance = fep.GetConversionDistance(reducedParam, classTable, true, runtimeCore); if (distance != (int)ProcedureDistance.InvalidDistance) { ret.Add(fep, distance); break; } } } return(ret); }
static void Main(string[] args) { Console.WriteLine("Press any key to start..."); Console.ReadKey(); using (var db = new Database("db")) { var config = new ReplicatorConfiguration(db, new URLEndpoint(new Uri("ws://localhost:5984/db"))) { Continuous = true }; var repl = new Replicator(config); repl.Start(); var key = new ConsoleKeyInfo(); var r = new Random(); do { Console.WriteLine("Press A to add document, Press E to end"); key = Console.ReadKey(); if (key.Key == ConsoleKey.A) { using (var doc = new MutableDocument()) { doc.SetInt("rand", r.Next()); db.Save(doc); } } } while (key.Key != ConsoleKey.E); repl.Stop(); while (repl.Status.Activity != ReplicatorActivityLevel.Stopped) { Console.WriteLine("Waiting for replicator to stop..."); Thread.Sleep(2000); } } }
public LeaderOnlyLockManager(MemberId myself, Replicator replicator, LeaderLocator leaderLocator, Locks localLocks, ReplicatedLockTokenStateMachine lockTokenStateMachine) { this._myself = myself; this._replicator = replicator; this._leaderLocator = leaderLocator; this._localLocks = localLocks; this._lockTokenStateMachine = lockTokenStateMachine; }
private void Start() { replicator = UnityFunctions.modules.GetComponentInChildren <Replicator>(); if (replicator == null) { replicator_button.interactable = false; } }
public ReplicatedIdRangeAcquirer(Replicator replicator, ReplicatedIdAllocationStateMachine idAllocationStateMachine, IDictionary <IdType, int> allocationSizes, MemberId me, LogProvider logProvider) { this._replicator = replicator; this._idAllocationStateMachine = idAllocationStateMachine; this._allocationSizes = allocationSizes; this._me = me; this._log = logProvider.getLog(this.GetType()); }
protected ReplicatorChaosSpec(ReplicatorChaosSpecConfig config) : base(config, typeof(ReplicatorChaosSpec)) { _cluster = Akka.Cluster.Cluster.Get(Sys); _timeout = Dilated(TimeSpan.FromSeconds(3)); _replicator = Sys.ActorOf(Replicator.Props(ReplicatorSettings.Create(Sys) .WithRole("backend") .WithGossipInterval(TimeSpan.FromSeconds(1))), "replicator"); }
private IActorRef StartReplicator(ActorSystem system) { return(system.ActorOf(Replicator.Props( ReplicatorSettings.Create(system) .WithGossipInterval(TimeSpan.FromSeconds(1)) .WithPruning(TimeSpan.FromSeconds(1), maxPruningDissemination)), "replicator")); }
// TODO: Clean up all the resolving, which now happens every time with special selection strategies. internal ReplicatedTokenHolder(TokenRegistry tokenRegistry, Replicator replicator, IdGeneratorFactory idGeneratorFactory, IdType tokenIdType, System.Func <StorageEngine> storageEngineSupplier, TokenType type, ReplicatedTokenCreator tokenCreator) : base(tokenRegistry) { this._replicator = replicator; this._idGeneratorFactory = idGeneratorFactory; this._tokenIdType = tokenIdType; this._type = type; this._storageEngineSupplier = storageEngineSupplier; this._tokenCreator = tokenCreator; }
public ReplicatorPruningSpec(ReplicatorPruningSpecConfig config) : base(config) { _cluster = Cluster.Cluster.Get(Sys); _timeout = Dilated(TimeSpan.FromSeconds(3)); _replicator = Sys.ActorOf(Replicator.Props(ReplicatorSettings.Create(Sys) .WithGossipInterval(TimeSpan.FromSeconds(1)) .WithPruning(pruningInterval: TimeSpan.FromSeconds(1), maxPruningDissemination: _maxPruningDissemination)), "replicator"); }
/// <inheritdoc /> public void Dispose() { Ended?.Invoke(this, null); Database?.Dispose(); Replicator?.Stop(); // Uncomment after DB019 (https://github.com/couchbase/couchbase-lite-net/issues/908) //_replicator?.Dispose(); HttpClient.Dispose(); }
public void TestReadOnlyConfiguration() { var config = CreateConfig(true, false, false); using (var repl = new Replicator(config)) { config = repl.Config; config.Invoking(c => c.ReplicatorType = ReplicatorType.PushAndPull) .ShouldThrow <InvalidOperationException>("because the configuration from a replicator should be read only"); } }
protected override void Dispose(bool disposing) { _repl?.Dispose(); _repl = null; base.Dispose(disposing); _otherDB.Delete(); _otherDB = null; }
private void Initialize() { m_dataPath = DataPath.Instance.Root; m_rep = Replicator.Instance; m_log = BoostLog.Instance; m_clients = ClientList.Instance; AbortWorker(); LoadClientList(); ProgressTimer.Interval = 500; ProgressTimer.Enabled = false; m_init = true; }
public void SetUp() { _replicator = new Replicator<int>(); }
//main constructor is private because BoostLog is a singleton //use BoostLog.Instance instead of new BoostLog() private BoostLog() { ServerId = ""; var source = "4-Tell Boost"; var logMsg = ""; try { //start logging to system event log source = ConfigurationManager.AppSettings.Get("LogSource") ?? "Unidentified"; logMsg = "4-Tell Event Log started for " + source; _eventLog = new EventLog("4-Tell") {Source = source}; //Read Gmail settings from web.config _gmailUsername = ConfigurationManager.AppSettings.Get("GmailUsername"); _gmailPassword = ConfigurationManager.AppSettings.Get("GmailPassword"); _gmailToAddress = ConfigurationManager.AppSettings.Get("GmailToAdress"); ServerId = ConfigurationManager.AppSettings.Get("ServerId"); var level = ConfigurationManager.AppSettings.Get("AdminReportLevel"); _adminReportType = GetReportLevel(level); var admin = new UserContact {Name = "Admin", Email = _gmailToAddress}; //Block logging for certain clients #if INCLUDE_REPLICATOR if (TableAccess.Instance != null) { _logBlockList = TableAccess.Instance.LogBlockList; //ConfigurationManager.AppSettings.Get("LogBlockList"); if (_logBlockList != null && _logBlockList.Any()) { logMsg += "\nLogging will be blocked for the following clients:\n" + _logBlockList.Aggregate((current, alias) => current + (alias + "\n")); } } //log any replicator startup issues logMsg += "\nInitializing Replicator"; _replicator = Replicator.Instance; if (_replicator == null) { logMsg += "\nReplicator instance is null"; Thread.Sleep(100); _replicator = Replicator.Instance; } if (_replicator != null) { logMsg += "\nInitializing DataLog"; //log any usage log issues _dataLog = DataLogProxy.Instance; if (_dataLog == null) { logMsg += "\nDataLog instance is null"; Thread.Sleep(100); _dataLog = DataLogProxy.Instance; } if (_dataLog != null) { if (!string.IsNullOrEmpty(_dataLog.ErrorText)) { _eventLog.WriteEntry(_dataLog.ErrorText, EventLogEntryType.Warning); } } } #endif _eventLog.WriteEntry(logMsg, EventLogEntryType.Information); } catch (Exception ex) { var errMsg = "Initialization Error for " + source + " Log: " + ex.Message; if (ex.InnerException != null) errMsg += "\nInner Exception: " + ex.InnerException.Message; if (string.IsNullOrEmpty(ex.StackTrace)) errMsg += "\nStack Trace:\n" + ex.StackTrace; if (logMsg != null) errMsg += "\nLog Message = " + logMsg; if (_eventLog != null) _eventLog.WriteEntry(errMsg, EventLogEntryType.Error); } }