示例#1
0
        public async Task SubscriptionWorkerShouldNotFailoverToErroredNodes()
        {
            var cluster = await CreateRaftCluster(numberOfNodes : 3);

            using (var store = GetDocumentStore(new Options
            {
                ReplicationFactor = 3,
                Server = cluster.Leader,
                DeleteDatabaseOnDispose = false
            }))
            {
                Servers.ForEach(x => x.ForTestingPurposesOnly().GatherVerboseDatabaseDisposeInformation = true);

                var mre = new AsyncManualResetEvent();
                using (var subscriptionManager = new DocumentSubscriptions(store))
                {
                    var reqEx = store.GetRequestExecutor();
                    var name  = subscriptionManager.Create(new SubscriptionCreationOptions <User>());

                    var subs = await SubscriptionFailoverWithWaitingChains.GetSubscription(name, store.Database, cluster.Nodes);

                    Assert.NotNull(subs);
                    await Cluster.WaitForRaftIndexToBeAppliedOnClusterNodesAsync(subs.SubscriptionId, cluster.Nodes);

                    await ActionWithLeader(async l => await WaitForResponsibleNode(l.ServerStore, store.Database, name, toBecomeNull: false));

                    Assert.True(WaitForValue(() => reqEx.Topology != null, true));
                    var topology    = reqEx.Topology;
                    var serverNode1 = topology.Nodes[0];
                    await reqEx.UpdateTopologyAsync(new RequestExecutor.UpdateTopologyParameters(serverNode1)
                    {
                        TimeoutInMs = 10_000
                    });
示例#2
0
        public async Task BasicCriteriaTest()
        {
            using (var store = GetDocumentStore())
                using (var subscriptionManager = new DocumentSubscriptions(store))
                {
                    await CreateDocuments(store, 1);

                    var lastEtag = store.GetLastWrittenEtag() ?? 0;
                    await CreateDocuments(store, 5);

                    var subscriptionCriteria = new SubscriptionCriteria
                    {
                        Collection       = "Things",
                        FilterJavaScript = " return this.Name == 'ThingNo3'",
                    };
                    var subsId = subscriptionManager.Create(subscriptionCriteria, lastEtag);
                    using (var subscription = subscriptionManager.Open <Thing>(new SubscriptionConnectionOptions()
                    {
                        SubscriptionId = subsId
                    }))
                    {
                        var list = new BlockingCollection <Thing>();
                        subscription.Subscribe(x =>
                        {
                            list.Add(x);
                        });
                        await subscription.StartAsync();

                        Thing thing;
                        Assert.True(list.TryTake(out thing, 5000));
                        Assert.Equal("ThingNo3", thing.Name);
                        Assert.False(list.TryTake(out thing, 50));
                    }
                }
        }
示例#3
0
        protected DocumentStoreBase()
        {
            InitializeEncryptor();

            LastEtagHolder     = new GlobalLastEtagHolder();
            AsyncSubscriptions = new AsyncDocumentSubscriptions(this);
            Subscriptions      = new DocumentSubscriptions(this);
        }
示例#4
0
        public async Task BasicCriteriaTest(bool useSsl)
        {
            string           dbName            = GetDatabaseName();
            X509Certificate2 clientCertificate = null;
            X509Certificate2 adminCertificate  = null;

            if (useSsl)
            {
                var certificates = Certificates.SetupServerAuthentication();
                adminCertificate  = Certificates.RegisterClientCertificate(certificates.ServerCertificate.Value, certificates.ClientCertificate1.Value, new Dictionary <string, DatabaseAccess>(), SecurityClearance.ClusterAdmin);
                clientCertificate = Certificates.RegisterClientCertificate(certificates.ServerCertificate.Value, certificates.ClientCertificate2.Value, new Dictionary <string, DatabaseAccess>
                {
                    [dbName] = DatabaseAccess.ReadWrite
                });
            }

            using (var store = GetDocumentStore(new Options
            {
                AdminCertificate = adminCertificate,
                ClientCertificate = clientCertificate,
                ModifyDatabaseName = s => dbName
            }))
            {
                using (var subscriptionManager = new DocumentSubscriptions(store))
                {
                    await CreateDocuments(store, 1);

                    var lastChangeVector = (await store.Maintenance.SendAsync(new GetStatisticsOperation())).DatabaseChangeVector;
                    await CreateDocuments(store, 5);

                    var subscriptionCreationParams = new SubscriptionCreationOptions()
                    {
                        Query        = "from Things where Name = 'ThingNo3'",
                        ChangeVector = lastChangeVector
                    };
                    var subsId = subscriptionManager.Create(subscriptionCreationParams);
                    using (var subscription = subscriptionManager.GetSubscriptionWorker <Thing>(new SubscriptionWorkerOptions(subsId)
                    {
                        TimeToWaitBeforeConnectionRetry = TimeSpan.FromSeconds(5)
                    }))
                    {
                        var list = new BlockingCollection <Thing>();
                        GC.KeepAlive(subscription.Run(x =>
                        {
                            foreach (var item in x.Items)
                            {
                                list.Add(item.Result);
                            }
                        }));

                        Thing thing;
                        Assert.True(list.TryTake(out thing, _reasonableWaitTime));
                        Assert.Equal("ThingNo3", thing.Name);
                        Assert.False(list.TryTake(out thing, 50));
                    }
                }
            }
        }
示例#5
0
        protected DocumentStoreBase()
        {
            InitializeEncryptor();

            LastEtagHolder             = new GlobalLastEtagHolder();
            TransactionRecoveryStorage = new VolatileOnlyTransactionRecoveryStorage();
            AsyncSubscriptions         = new AsyncDocumentSubscriptions(this);
            Subscriptions = new DocumentSubscriptions(this);
        }
示例#6
0
		protected DocumentStoreBase()
		{
			InitializeEncryptor();

			LastEtagHolder = new GlobalLastEtagHolder();
			TransactionRecoveryStorage = new VolatileOnlyTransactionRecoveryStorage();
			AsyncSubscriptions = new AsyncDocumentSubscriptions(this);
			Subscriptions = new DocumentSubscriptions(this);
		}
示例#7
0
 protected DocumentStoreBase()
 {
     Subscriptions = new DocumentSubscriptions(this);
 }
示例#8
0
        public async Task CriteriaScriptWithTransformation(bool useSsl)
        {
            string           dbName            = GetDatabaseName();
            X509Certificate2 clientCertificate = null;
            X509Certificate2 adminCertificate  = null;

            if (useSsl)
            {
                var serverCertPath = SetupServerAuthentication();
                adminCertificate  = AskServerForClientCertificate(serverCertPath, new Dictionary <string, DatabaseAccess>(), SecurityClearance.ClusterAdmin);
                clientCertificate = AskServerForClientCertificate(serverCertPath, new Dictionary <string, DatabaseAccess>
                {
                    [dbName] = DatabaseAccess.ReadWrite,
                });
            }

            using (var store = GetDocumentStore(new Options
            {
                AdminCertificate = adminCertificate,
                ClientCertificate = clientCertificate,
                ModifyDatabaseName = s => dbName
            }))
            {
                using (var subscriptionManager = new DocumentSubscriptions(store))
                {
                    await CreateDocuments(store, 1);

                    var lastChangeVector = (await store.Admin.SendAsync(new GetStatisticsOperation())).DatabaseChangeVector;
                    await CreateDocuments(store, 6);

                    var subscriptionCreationParams = new SubscriptionCreationOptions()
                    {
                        Query        = @"
declare function project(d) {
    var namSuffix = parseInt(d.Name.replace('ThingNo', ''));  
    if (namSuffix <= 2){
        return false;
    }
    else if (namSuffix == 3){
        return null;
    }
    else if (namSuffix == 4){
        return d;
    }
    return {Name: 'foo', OtherDoc:load('things/6-A')}
}
from Things as d
select project(d)
",
                        ChangeVector = lastChangeVector
                    };

                    var subsId = subscriptionManager.Create(subscriptionCreationParams);
                    using (var subscription = subscriptionManager.Open <BlittableJsonReaderObject>(new SubscriptionConnectionOptions(subsId)))
                    {
                        using (store.GetRequestExecutor().ContextPool.AllocateOperationContext(out JsonOperationContext context))
                        {
                            var list = new BlockingCollection <BlittableJsonReaderObject>();

                            GC.KeepAlive(subscription.Run(x =>
                            {
                                foreach (var item in x.Items)
                                {
                                    list.Add(context.ReadObject(item.Result, "test"));
                                }
                            }));

                            BlittableJsonReaderObject thing;

                            Assert.True(list.TryTake(out thing, 5000));
                            dynamic dynamicThing = new DynamicBlittableJson(thing);
                            Assert.Equal("ThingNo4", dynamicThing.Name);


                            Assert.True(list.TryTake(out thing, 5000));
                            dynamicThing = new DynamicBlittableJson(thing);
                            Assert.Equal("foo", dynamicThing.Name);
                            Assert.Equal("ThingNo4", dynamicThing.OtherDoc.Name);

                            Assert.False(list.TryTake(out thing, 50));
                        }
                    }
                }
            }
        }
示例#9
0
        public Document(string mapFile, Map map, Game game)
        {
            MapFile     = mapFile;
            Map         = map;
            Game        = game;
            Environment = new GameEnvironment(game);
            MapFileName = mapFile == null
                              ? DocumentManager.GetUntitledDocumentName()
                              : Path.GetFileName(mapFile);

            SelectListTransform = Matrix4.Identity;

            _subscriptions = new DocumentSubscriptions(this);

            _memory = new DocumentMemory();

            var cam = Map.GetActiveCamera();

            if (cam != null)
            {
                _memory.SetCamera(cam.EyePosition, cam.LookPosition);
            }

            Selection = new SelectionManager(this);
            History   = new HistoryManager(this);
            if (Map.GridSpacing <= 0)
            {
                Map.GridSpacing = Grid.DefaultSize;
            }

            try
            {
                GameData = GameDataProvider.GetGameDataFromFiles(game.Fgds.Select(f => f.Path));
            }
            catch (ProviderException)
            {
                // TODO: Error logging
                GameData = new GameData();
            }

            if (game.OverrideMapSize)
            {
                GameData.MapSizeLow  = game.OverrideMapSizeLow;
                GameData.MapSizeHigh = game.OverrideMapSizeHigh;
            }

            TextureCollection = TextureProvider.CreateCollection(Environment.GetGameDirectories(), Game.AdditionalPackages, Game.GetTextureBlacklist(), Game.GetTextureWhitelist());
            /* .Union(GameData.MaterialExclusions) */ // todo material exclusions

            var texList = Map.GetAllTextures();
            var items   = TextureCollection.GetItems(texList);

            TextureProvider.LoadTextureItems(items);

            //Map.PostLoadProcess(GameData, GetTexture, SettingsManager.GetSpecialTextureOpacity);
            Map.PostLoadProcess(GameData,
                                GetTexture,
                                SettingsManager.GetSpecialTextureOpacity,
                                Chisel.Settings.View.GloballyDisableTransparency);
            Map.UpdateDecals(this);
            Map.UpdateModels(this);
            Map.UpdateSprites(this);

            HelperManager = new HelperManager(this);
            Renderer      = new RenderManager(this);

            if (MapFile != null)
            {
                Mediator.Publish(EditorMediator.FileOpened, MapFile);
            }

            // Autosaving
            if (Game.Autosave)
            {
                var at = Math.Max(1, Game.AutosaveTime);
                Scheduler.Schedule(this, Autosave, TimeSpan.FromMinutes(at));
            }
        }