/// <summary> /// Test that, if the writer crashes at the very beginning of a segment, /// before any transactions are written, that the next newEpoch() call /// returns the prior segment txid as its most recent segment. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestNewEpochAtBeginningOfSegment() { journal.NewEpoch(FakeNsinfo, 1); journal.StartLogSegment(MakeRI(1), 1, NameNodeLayoutVersion.CurrentLayoutVersion); journal.Journal(MakeRI(2), 1, 1, 2, QJMTestUtil.CreateTxnData(1, 2)); journal.FinalizeLogSegment(MakeRI(3), 1, 2); journal.StartLogSegment(MakeRI(4), 3, NameNodeLayoutVersion.CurrentLayoutVersion); QJournalProtocolProtos.NewEpochResponseProto resp = journal.NewEpoch(FakeNsinfo, 2); NUnit.Framework.Assert.AreEqual(1, resp.GetLastSegmentTxId()); }
/// <exception cref="System.Exception"/> public virtual void TestReturnsSegmentInfoAtEpochTransition() { ch.NewEpoch(1).Get(); ch.SetEpoch(1); ch.StartLogSegment(1, NameNodeLayoutVersion.CurrentLayoutVersion).Get(); ch.SendEdits(1L, 1, 2, QJMTestUtil.CreateTxnData(1, 2)).Get(); // Switch to a new epoch without closing earlier segment QJournalProtocolProtos.NewEpochResponseProto response = ch.NewEpoch(2).Get(); ch.SetEpoch(2); NUnit.Framework.Assert.AreEqual(1, response.GetLastSegmentTxId()); ch.FinalizeLogSegment(1, 2).Get(); // Switch to a new epoch after just closing the earlier segment. response = ch.NewEpoch(3).Get(); ch.SetEpoch(3); NUnit.Framework.Assert.AreEqual(1, response.GetLastSegmentTxId()); // Start a segment but don't write anything, check newEpoch segment info ch.StartLogSegment(3, NameNodeLayoutVersion.CurrentLayoutVersion).Get(); response = ch.NewEpoch(4).Get(); ch.SetEpoch(4); // Because the new segment is empty, it is equivalent to not having // started writing it. Hence, we should return the prior segment txid. NUnit.Framework.Assert.AreEqual(1, response.GetLastSegmentTxId()); }