/// <summary>
 /// Constructs a new, empty set that orders its elements according to
 /// their <seealso cref="Comparable natural ordering"/>.
 /// </summary>
 public ConcurrentSkipListSet()
 {
     m = new ConcurrentSkipListMap <E, Object>();
 }
Exemplo n.º 2
0
        public virtual void TestCheckCommitFromReadLargeFileUpload()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with large file upload option
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration config = new NfsConfiguration();

            config.SetBoolean(NfsConfigKeys.LargeFileUpload, true);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (config), false, config);
            FileHandle h = new FileHandle(1);

            // fake handle for "/dumpFilePath"
            OpenFileCtx.COMMIT_STATUS ret;
            WriteManager wm = new WriteManager(new ShellBasedIdMapping(config), config, false
                                               );

            NUnit.Framework.Assert.IsTrue(wm.AddOpenFileStream(h, ctx));
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 0));
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                            , ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errIo, wm.CommitBeforeRead(dfsClient
                                                                                      , h, 0));
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)6);
            ctx.SetNextOffsetForTest((long)10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, ch, 1, attr, false);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitDoSync, status);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitFinished, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 5));
            // Test request with sequential writes
            status = ctx.CheckCommitInternal(9, ch, 1, attr, true);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait
                                          );
            ret = ctx.CheckCommit(dfsClient, 9, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 9));
            // Test request with non-sequential writes
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 0);
            ret = ctx.CheckCommit(dfsClient, 16, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess, ret
                                            );
            NUnit.Framework.Assert.AreEqual(0, commits.Count);
            // commit triggered by read doesn't wait
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 16));
            // Test request with zero commit offset
            // There is one pending write [10,15]
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(0, commits.Count);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 0));
            // Empty pending writes
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(10, 15)
                                       );
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 0));
        }
Exemplo n.º 3
0
        public virtual void TestCheckCommit()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS, which
            // includes COMMIT_FINISHED, COMMIT_WAIT, COMMIT_INACTIVE_CTX,
            // COMMIT_INACTIVE_WITH_PENDING_WRITE, COMMIT_ERROR, and COMMIT_DO_SYNC.
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, false);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (conf), false, conf);

            OpenFileCtx.COMMIT_STATUS ret;
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx);
            ctx.GetPendingWritesForTest()[new OffsetRange(5, 10)] = new WriteCtx(null, 0, 0,
                                                                                 0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                          );
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)10);
            ctx.SetNextOffsetForTest(10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            status = ctx.CheckCommitInternal(10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            ret = ctx.CheckCommit(dfsClient, 10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 0);
            ret = ctx.CheckCommit(dfsClient, 11, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            long key = commits.FirstKey();

            NUnit.Framework.Assert.IsTrue(key == 11);
            // Test request with zero commit offset
            Sharpen.Collections.Remove(commits, System.Convert.ToInt64(11));
            // There is one pending write [5,10]
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            key = commits.FirstKey();
            NUnit.Framework.Assert.IsTrue(key == 9);
            // Empty pending writes
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(5, 10));
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
        }
Exemplo n.º 4
0
        public virtual void TestCheckCommitLargeFileUpload()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with
            // large file upload option.
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, true);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (conf), false, conf);

            OpenFileCtx.COMMIT_STATUS ret;
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx);
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                          );
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)8);
            ctx.SetNextOffsetForTest(10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            // Test commit sequential writes
            status = ctx.CheckCommitInternal(10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait
                                          );
            ret = ctx.CheckCommit(dfsClient, 10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            // Test commit non-sequential writes
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            ret = ctx.CheckCommit(dfsClient, 16, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess
                                          );
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            // Test request with zero commit offset
            Sharpen.Collections.Remove(commits, System.Convert.ToInt64(10));
            // There is one pending write [10,15]
            ret = ctx.CheckCommitInternal(0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            ret = ctx.CheckCommitInternal(9, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 2);
            // Empty pending writes. nextOffset=10, flushed pos=8
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(10, 15)
                                       );
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            // Empty pending writes
            ctx.SetNextOffsetForTest((long)8);
            // flushed pos = 8
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
        }