예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSlaveWritingFirstAfterStoryCopy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleSlaveWritingFirstAfterStoryCopy()
        {
            // Given
            ISet <long> expected = new HashSet <object>();

            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;
            HighlyAvailableGraphDatabase  slave   = cluster.AnySlave;

            // When
            expected.Add(CreateOneNode(master));
            cluster.Sync();

            // ... crash the slave
            File slaveStoreDirectory = cluster.GetDatabaseDir(slave);

            ClusterManager.RepairKit shutdownSlave = cluster.Shutdown(slave);
            deleteRecursively(slaveStoreDirectory);

            // ... and slave copy store from master
            slave = shutdownSlave.Repair();
            // ... and first write after crash occurs on salve
            expected.Add(CreateOneNode(slave));
            cluster.Sync();

            // Then
            assertEquals(expected, CollectIds(master));
            assertEquals(expected, CollectIds(slave));
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCopyStoreFromMasterIfBranched() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCopyStoreFromMasterIfBranched()
        {
            // GIVEN
            File           dir            = _directory.directory();
            ClusterManager clusterManager = _life.add(new ClusterManager.Builder(dir)
                                                      .withCluster(clusterOfSize(2)).build());

            ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
            cluster.Await(allSeesAllAsAvailable());
            CreateNode(cluster.Master, "A");
            cluster.Sync();

            // WHEN
            HighlyAvailableGraphDatabase slave = cluster.AnySlave;
            File databaseDir = slave.DatabaseLayout().databaseDirectory();

            ClusterManager.RepairKit     starter = cluster.Shutdown(slave);
            HighlyAvailableGraphDatabase master  = cluster.Master;

            CreateNode(master, "B1");
            CreateNode(master, "C");
            CreateNodeOffline(databaseDir, "B2");
            slave = starter.Repair();

            // THEN
            cluster.Await(allSeesAllAsAvailable());
            slave.BeginTx().close();
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminatedTransactionDoesNotForceUpdatePulling()
        public virtual void TerminatedTransactionDoesNotForceUpdatePulling()
        {
            int testTxsOnMaster = 42;

            ClusterManager.ManagedCluster cluster = ClusterRule.withSharedSetting(HaSettings.pull_interval, "0s").withSharedSetting(HaSettings.tx_push_factor, "0").startCluster();

            HighlyAvailableGraphDatabase master = cluster.Master;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
            HighlyAvailableGraphDatabase slave = cluster.AnySlave;

            CreateNodeOn(master);
            cluster.Sync();

            long lastClosedTxIdOnMaster = LastClosedTxIdOn(master);
            long lastClosedTxIdOnSlave  = LastClosedTxIdOn(slave);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveTxStarted = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent slaveTxStarted = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveShouldCommit = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent slaveShouldCommit = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<org.neo4j.graphdb.Transaction> slaveTx = new java.util.concurrent.atomic.AtomicReference<>();
            AtomicReference <Transaction> slaveTx = new AtomicReference <Transaction>();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> slaveCommit = java.util.concurrent.Executors.newSingleThreadExecutor().submit(() ->
            Future <object> slaveCommit = Executors.newSingleThreadExecutor().submit(() =>
            {
                using (Transaction tx = slave.BeginTx())
                {
                    slaveTx.set(tx);
                    slaveTxStarted.Signal();
                    Await(slaveShouldCommit);
                    tx.success();
                }
            });

            Await(slaveTxStarted);
            CreateNodesOn(master, testTxsOnMaster);

            assertNotNull(slaveTx.get());
            slaveTx.get().terminate();
            slaveShouldCommit.Signal();

            try
            {
                slaveCommit.get();
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(ExecutionException)));
                assertThat(e.InnerException, instanceOf(typeof(TransientTransactionFailureException)));
            }

            assertEquals(lastClosedTxIdOnMaster + testTxsOnMaster, LastClosedTxIdOn(master));
            assertEquals(lastClosedTxIdOnSlave, LastClosedTxIdOn(slave));
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void lastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                RunSomeTransactions(cluster.Master);
                cluster.Sync();

                HighlyAvailableGraphDatabase slave      = cluster.AnySlave;
                DatabaseLayout           databaseLayout = slave.DatabaseLayout();
                ClusterManager.RepairKit slaveRepairKit = cluster.Shutdown(slave);

                ClearLastTransactionCommitTimestampField(databaseLayout);
                DeleteLogs(databaseLayout);

                HighlyAvailableGraphDatabase repairedSlave = slaveRepairKit.Repair();
                cluster.Await(allSeesAllAsAvailable());

                assertEquals(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.UNKNOWN_TX_COMMIT_TIMESTAMP, LastCommittedTxTimestamp(repairedSlave));
            }
            finally
            {
                clusterManager.Stop();
            }
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void lastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                RunSomeTransactions(cluster.Master);
                cluster.Sync();

                HighlyAvailableGraphDatabase slave      = cluster.AnySlave;
                DatabaseLayout           databaseLayout = slave.DatabaseLayout();
                ClusterManager.RepairKit slaveRepairKit = cluster.Shutdown(slave);

                ClearLastTransactionCommitTimestampField(databaseLayout);

                HighlyAvailableGraphDatabase repairedSlave = slaveRepairKit.Repair();
                cluster.Await(allSeesAllAsAvailable());

                assertEquals(LastCommittedTxTimestamp(cluster.Master), LastCommittedTxTimestamp(repairedSlave));
            }
            finally
            {
                clusterManager.Stop();
            }
        }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateConstraintOnMaster()
            public virtual void ShouldCreateConstraintOnMaster()
            {
                // given
                ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
                HighlyAvailableGraphDatabase  master  = cluster.Master;
                string type = type(0);
                string key  = key(0);

                // when
                using (Transaction tx = master.BeginTx())
                {
                    CreateConstraint(master, type, key);
                    tx.Success();
                }

                cluster.Sync();

                // then
                foreach (HighlyAvailableGraphDatabase clusterMember in cluster.AllMembers)
                {
                    using (Transaction tx = clusterMember.BeginTx())
                    {
                        ConstraintDefinition constraint = GetConstraint(clusterMember, type, key);
                        ValidateLabelOrRelationshipType(constraint, type);
                        assertEquals(key, single(constraint.PropertyKeys));
                        tx.Success();
                    }
                }
            }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveConstraints()
            public virtual void ShouldRemoveConstraints()
            {
                // given
                ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
                HighlyAvailableGraphDatabase  master  = cluster.Master;
                string type = type(2);
                string key  = key(2);

                long constraintCountBefore;
                long indexCountBefore;

                using (Transaction tx = master.BeginTx())
                {
                    constraintCountBefore = count(master.Schema().Constraints);
                    indexCountBefore      = count(master.Schema().Indexes);
                    CreateConstraint(master, type, key);
                    tx.Success();
                }
                cluster.Sync();

                // and given I have some data for the constraint
                CreateEntityInTx(cluster.AnySlave, type, key, "Foo");

                // when
                using (Transaction tx = master.BeginTx())
                {
                    GetConstraint(master, type, key).drop();
                    tx.Success();
                }
                cluster.Sync();

                // then the constraint should be gone, and not be enforced anymore
                foreach (HighlyAvailableGraphDatabase clusterMember in cluster.AllMembers)
                {
                    using (Transaction tx = clusterMember.BeginTx())
                    {
                        assertNull(GetConstraint(clusterMember, type, key));
                        assertNull(GetIndex(clusterMember, type, key));
                        CreateConstraintViolation(clusterMember, type, key, "Foo");
                        tx.Success();
                    }
                }
            }
예제 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void onlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void OnlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy()
        {
            /*
             * The master has an index that is online.
             * Then a slave comes online and contacts the master to get copies of the store files.
             * Because the index is online, it should be copied, and the slave should successfully bring the index online.
             */

            // GIVEN
            ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();

            ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, _controlledProviderDescriptor.name()).startCluster();
            cluster.Await(allSeesAllAsAvailable(), 120);

            HighlyAvailableGraphDatabase slave = cluster.AnySlave;

            // All slaves in the cluster, except the one I care about, proceed as normal
            ProceedAsNormalWithIndexPopulationOnAllSlavesExcept(dbFactory, cluster, slave);

            // A slave is offline, and has no store files
            ClusterManager.RepairKit slaveDown = BringSlaveOfflineAndRemoveStoreFiles(cluster, slave);

            // And I create an index on the master, and wait for population to start
            HighlyAvailableGraphDatabase master = cluster.Master;
            IDictionary <object, Node>   data   = CreateSomeData(master);

            CreateIndex(master);
            dbFactory.AwaitPopulationStarted(master);

            // And the population finishes
            dbFactory.TriggerFinish(master);
            IndexDefinition index;

            using (Transaction tx = master.BeginTx())
            {
                index = single(master.Schema().Indexes);
                AwaitIndexOnline(index, master, data);
                tx.Success();
            }

            // WHEN the slave comes online after population has finished on the master
            slave = slaveDown.Repair();
            cluster.Await(allSeesAllAsAvailable());
            cluster.Sync();

            // THEN the index should work on the slave
            dbFactory.TriggerFinish(slave);
            using (Transaction tx = slave.BeginTx())
            {
                AwaitIndexOnline(index, slave, data);
                tx.Success();
            }
        }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void creatingIndexOnMasterShouldHaveSlavesBuildItAsWell() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CreatingIndexOnMasterShouldHaveSlavesBuildItAsWell()
        {
            // GIVEN
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;
            IDictionary <object, Node>    data    = CreateSomeData(master);

            // WHEN
            IndexDefinition index = CreateIndex(master);

            cluster.Sync();

            // THEN
            AwaitIndexOnline(index, cluster, data);
        }
예제 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void slavesTerminateOrReadConsistentDataWhenApplyingBatchLargerThanSafeZone() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SlavesTerminateOrReadConsistentDataWhenApplyingBatchLargerThanSafeZone()
        {
            long safeZone = TimeUnit.MILLISECONDS.toSeconds(0);

            ClusterRule.withSharedSetting(HaSettings.id_reuse_safe_zone_time, safeZone.ToString());
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;

            // when
            // ... slaves and master has node with long string property
            long entityId = Action.createInitialEntity(master);

            cluster.Sync();
            // ... and property is removed on master
            Action.removeProperties(master, entityId);
            Thread.Sleep(100);
            // ... and maintenance is called to make sure "safe" ids are freed to be reused
            ForceMaintenance(master);
            // ... and a new property is created on master that
            Action.setNewProperties(master, entityId);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
            HighlyAvailableGraphDatabase slave = cluster.AnySlave;
            Race race = new Race();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean(false);
            AtomicBoolean end = new AtomicBoolean(false);

            for (int i = 0; i < READER_CONTESTANTS; i++)
            {
                race.AddContestant(ReadContestant(Action, entityId, slave, end));
            }

            race.AddContestant(PullUpdatesContestant(slave, end));

            race.Go();
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void Setup()
            {
                // setup a cluster with some data and entries in log files in fully functional and shutdown state
                ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();

                try
                {
                    cluster.Await(allSeesAllAsAvailable());

                    OldMaster = cluster.Master;
                    CreateSomeData(OldMaster);
                    cluster.Sync();

                    OldSlave1 = cluster.AnySlave;
                    OldSlave2 = cluster.GetAnySlave(OldSlave1);
                }
                finally
                {
                    ClusterRule.shutdownCluster();
                }
                AssertAllStoreConsistent(cluster);
            }
예제 #12
0
        /// <summary>
        /// Main difference to <seealso cref="shouldCopyStoreFromMasterIfBranched()"/> is that no instances are shut down
        /// during the course of the test. This to test functionality of some internal components being restarted.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldCopyStoreFromMasterIfBranchedInLiveScenario() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCopyStoreFromMasterIfBranchedInLiveScenario()
        {
            // GIVEN a cluster of 3, all having the same data (node A)
            // thor is whoever is the master to begin with
            // odin is whoever is picked as _the_ slave given thor as initial master
            File           storeDirectory = _directory.directory();
            ClusterManager clusterManager = _life.add(new ClusterManager.Builder(storeDirectory)
                                                      .withSharedConfig(stringMap(HaSettings.tx_push_factor.name(), "0", HaSettings.pull_interval.name(), "0")).build());

            ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
            cluster.Await(allSeesAllAsAvailable());
            HighlyAvailableGraphDatabase thor = cluster.Master;
            string indexName = "valhalla";

            CreateNode(thor, "A", AndIndexInto(indexName));
            cluster.Sync();

            // WHEN creating a node B1 on thor (note the disabled cluster transaction propagation)
            CreateNode(thor, "B1", AndIndexInto(indexName));
            // and right after that failing the master so that it falls out of the cluster
            HighlyAvailableGraphDatabase odin = cluster.AnySlave;

            cluster.Info(format("%n   ==== TAMPERING WITH " + thor + "'s CABLES ====%n"));
            ClusterManager.RepairKit thorRepairKit = cluster.Fail(thor);
            // try to create a transaction on odin until it succeeds
            cluster.Await(ClusterManager.masterAvailable(thor));
            cluster.Await(ClusterManager.memberThinksItIsRole(odin, HighAvailabilityModeSwitcher.MASTER));
            assertTrue(odin.Master);
            RetryOnTransactionFailure(odin, db => createNode(db, "B2", AndIndexInto(indexName)));
            // perform transactions so that index files changes under the hood
            ISet <File> odinLuceneFilesBefore = Iterables.asSet(GatherLuceneFiles(odin, indexName));

            for (char prefix = 'C'; !Changed(odinLuceneFilesBefore, Iterables.asSet(GatherLuceneFiles(odin, indexName))); prefix++)
            {
                char fixedPrefix = prefix;
                RetryOnTransactionFailure(odin, db => createNodes(odin, fixedPrefix.ToString(), 10_000, AndIndexInto(indexName)));
                cluster.Force();                         // Force will most likely cause lucene explicit indexes to commit and change file structure
            }
            // so anyways, when thor comes back into the cluster
            cluster.Info(format("%n   ==== REPAIRING CABLES ====%n"));
            cluster.Await(memberThinksItIsRole(thor, UNKNOWN));
            BranchMonitor thorHasBranched = InstallBranchedDataMonitor(cluster.GetMonitorsByDatabase(thor));

            thorRepairKit.Repair();
            cluster.Await(memberThinksItIsRole(thor, SLAVE));
            cluster.Await(memberThinksItIsRole(odin, MASTER));
            cluster.Await(allSeesAllAsAvailable());
            assertFalse(thor.Master);
            assertTrue("No store-copy performed", thorHasBranched.CopyCompleted);
            assertTrue("Store-copy unsuccessful", thorHasBranched.CopySuccessful);

            // Now do some more transactions on current master (odin) and have thor pull those
            for (int i = 0; i < 3; i++)
            {
                int ii = i;
                RetryOnTransactionFailure(odin, db => createNodes(odin, ("" + ii).ToString(), 10, AndIndexInto(indexName)));
                cluster.Sync();
                cluster.Force();
            }

            // THEN thor should be a slave, having copied a store from master and good to go
            assertFalse(HasNode(thor, "B1"));
            assertTrue(HasNode(thor, "B2"));
            assertTrue(HasNode(thor, "C-0"));
            assertTrue(HasNode(thor, "0-0"));
            assertTrue(HasNode(odin, "0-0"));
        }
예제 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void populatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PopulatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy()
        {
            /*
             * The master has an index that is currently populating.
             * Then a slave comes online and contacts the master to get copies of the store files.
             * Because the index is still populating, it won't be copied. Instead the slave will build its own.
             * We want to observe that the slave builds an index that eventually comes online.
             */

            // GIVEN
            ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory(_isMaster);

            ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, NativeLuceneFusionIndexProviderFactory20.DESCRIPTOR.name()).startCluster();

            try
            {
                cluster.Await(allSeesAllAsAvailable());

                HighlyAvailableGraphDatabase slave = cluster.AnySlave;

                // A slave is offline, and has no store files
                ClusterManager.RepairKit slaveDown = BringSlaveOfflineAndRemoveStoreFiles(cluster, slave);

                // And I create an index on the master, and wait for population to start
                HighlyAvailableGraphDatabase master = cluster.Master;
                IDictionary <object, Node>   data   = CreateSomeData(master);
                CreateIndex(master);
                dbFactory.AwaitPopulationStarted(master);

                // WHEN the slave comes online before population has finished on the master
                slave = slaveDown.Repair();
                cluster.Await(allSeesAllAsAvailable(), 180);
                cluster.Sync();

                // THEN, population should finish successfully on both master and slave
                dbFactory.TriggerFinish(master);

                // Check master
                IndexDefinition index;
                using (Transaction tx = master.BeginTx())
                {
                    index = single(master.Schema().Indexes);
                    AwaitIndexOnline(index, master, data);
                    tx.Success();
                }

                // Check slave
                using (Transaction tx = slave.BeginTx())
                {
                    AwaitIndexOnline(index, slave, data);
                    tx.Success();
                }
            }
            finally
            {
                foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers)
                {
                    dbFactory.TriggerFinish(db);
                }
            }
        }
예제 #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void oneRound() throws Throwable
        private void OneRound()
        {
            // GIVEN a cluster and a node
            const string key = "key";

            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService master = cluster.getMaster();
            GraphDatabaseService master = cluster.Master;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long nodeId = createNode(master);
            long nodeId = CreateNode(master);

            cluster.Sync();

            // and a bunch of workers contending on that node, each changing it
            Workers <ThreadStart> transactors = new Workers <ThreadStart>("Transactors");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger successes = new java.util.concurrent.atomic.AtomicInteger();
            AtomicInteger successes = new AtomicInteger();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean end = new AtomicBoolean();

            for (int i = 0; i < 10; i++)
            {
                transactors.Start(() =>
                {
                    Random random = ThreadLocalRandom.current();
                    while (!end.get())
                    {
                        bool committed = true;
                        try
                        {
                            using (Transaction tx = master.BeginTx())
                            {
                                Node node = master.GetNodeById(nodeId);

                                // Acquiring lock, read int property value, increment, set incremented int property
                                // should not break under any circumstances.
                                tx.acquireWriteLock(node);
                                node.setProperty(key, ( int? )node.getProperty(key, 0) + 1);
                                // Throw in relationship for good measure
                                node.createRelationshipTo(master.CreateNode(), TEST);

                                Thread.Sleep(random.Next(1_000));
                                tx.success();
                            }
                        }
                        catch (Exception)
                        {
                            // It's OK
                            committed = false;
                        }
                        if (committed)
                        {
                            successes.incrementAndGet();
                        }
                    }
                });
            }

            // WHEN entering a period of induced cluster instabilities
            ReelectTheSameMasterMakingItGoToPendingAndBack(cluster);

            // ... letting transactions run a bit after the role switch as well.
            long targetSuccesses = successes.get() + 20;

            while (successes.get() < targetSuccesses)
            {
                Thread.Sleep(100);
            }
            end.set(true);
            transactors.AwaitAndThrowOnError();

            // THEN verify that the count is equal to the number of successful transactions
            assertEquals(successes.get(), GetNodePropertyValue(master, nodeId, key));
        }
예제 #15
0
 private static void AssertNodeExists(ClusterManager.ManagedCluster cluster, object value)
 {
     cluster.Sync();
     AssertNodeExists(cluster.Master, value);
 }
예제 #16
0
 private void CreateNode(ClusterManager.ManagedCluster cluster)
 {
     CreateNode(cluster.Master);
     cluster.Sync();
 }