Exemple #1
0
        public virtual void TestSingleThreaded()
        {
            Configuration      conf    = new Configuration();
            MiniJournalCluster cluster = new MiniJournalCluster.Builder(conf).Build();
            URI uri = cluster.GetQuorumJournalURI(Jid);
            QuorumJournalManager qjm = new QuorumJournalManager(conf, uri, FakeNsinfo);

            try
            {
                qjm.Format(FakeNsinfo);
            }
            finally
            {
                qjm.Close();
            }
            try
            {
                // With no failures or contention, epochs should increase one-by-one
                for (int i = 0; i < 5; i++)
                {
                    qjm = new QuorumJournalManager(conf, uri, FakeNsinfo);
                    try
                    {
                        qjm.CreateNewUniqueEpoch();
                        NUnit.Framework.Assert.AreEqual(i + 1, qjm.GetLoggerSetForTests().GetEpoch());
                    }
                    finally
                    {
                        qjm.Close();
                    }
                }
                long prevEpoch = 5;
                // With some failures injected, it should still always increase, perhaps
                // skipping some
                for (int i_1 = 0; i_1 < 20; i_1++)
                {
                    long newEpoch = -1;
                    while (true)
                    {
                        qjm = new QuorumJournalManager(conf, uri, FakeNsinfo, new TestEpochsAreUnique.FaultyLoggerFactory
                                                           (this));
                        try
                        {
                            qjm.CreateNewUniqueEpoch();
                            newEpoch = qjm.GetLoggerSetForTests().GetEpoch();
                            break;
                        }
                        catch (IOException)
                        {
                        }
                        finally
                        {
                            // It's OK to fail to create an epoch, since we randomly inject
                            // faults. It's possible we'll inject faults in too many of the
                            // underlying nodes, and a failure is expected in that case
                            qjm.Close();
                        }
                    }
                    Log.Info("Created epoch " + newEpoch);
                    NUnit.Framework.Assert.IsTrue("New epoch " + newEpoch + " should be greater than previous "
                                                  + prevEpoch, newEpoch > prevEpoch);
                    prevEpoch = newEpoch;
                }
            }
            finally
            {
                cluster.Shutdown();
            }
        }