Example #1
0
        public virtual void TestMoveSpecificPaths()
        {
            Log.Info("testMoveSpecificPaths");
            Path foo      = new Path("/foo");
            Path barFile  = new Path(foo, "bar");
            Path foo2     = new Path("/foo2");
            Path bar2File = new Path(foo2, "bar2");
            IDictionary <Path, BlockStoragePolicy> policyMap = Maps.NewHashMap();

            policyMap[foo]  = Cold;
            policyMap[foo2] = Warm;
            TestStorageMover.NamespaceScheme nsScheme = new TestStorageMover.NamespaceScheme(
                Arrays.AsList(foo, foo2), Arrays.AsList(barFile, bar2File), BlockSize, null, policyMap
                );
            TestStorageMover.ClusterScheme clusterScheme = new TestStorageMover.ClusterScheme
                                                               (DefaultConf, NumDatanodes, Repl, GenStorageTypes(NumDatanodes), null);
            TestStorageMover.MigrationTest test = new TestStorageMover.MigrationTest(this, clusterScheme
                                                                                     , nsScheme);
            test.SetupCluster();
            try
            {
                test.PrepareNamespace();
                test.SetStoragePolicy();
                IDictionary <URI, IList <Path> > map = Mover.Cli.GetNameNodePathsToMove(test.conf, "-p"
                                                                                        , "/foo/bar", "/foo2");
                int result = Org.Apache.Hadoop.Hdfs.Server.Mover.Mover.Run(map, test.conf);
                NUnit.Framework.Assert.AreEqual(ExitStatus.Success.GetExitCode(), result);
                Sharpen.Thread.Sleep(5000);
                test.Verify(true);
            }
            finally
            {
                test.ShutdownCluster();
            }
        }
Example #2
0
        public virtual void TestMigrateOpenFileToArchival()
        {
            Log.Info("testMigrateOpenFileToArchival");
            Path fooDir = new Path("/foo");
            IDictionary <Path, BlockStoragePolicy> policyMap = Maps.NewHashMap();

            policyMap[fooDir] = Cold;
            TestStorageMover.NamespaceScheme nsScheme = new TestStorageMover.NamespaceScheme(
                Arrays.AsList(fooDir), null, BlockSize, null, policyMap);
            TestStorageMover.ClusterScheme clusterScheme = new TestStorageMover.ClusterScheme
                                                               (DefaultConf, NumDatanodes, Repl, GenStorageTypes(NumDatanodes), null);
            TestStorageMover.MigrationTest test = new TestStorageMover.MigrationTest(this, clusterScheme
                                                                                     , nsScheme);
            test.SetupCluster();
            // create an open file
            Banner("writing to file /foo/bar");
            Path barFile = new Path(fooDir, "bar");

            DFSTestUtil.CreateFile(test.dfs, barFile, BlockSize, (short)1, 0L);
            FSDataOutputStream @out = test.dfs.Append(barFile);

            @out.WriteBytes("hello, ");
            ((DFSOutputStream)@out.GetWrappedStream()).Hsync();
            try
            {
                Banner("start data migration");
                test.SetStoragePolicy();
                // set /foo to COLD
                test.Migrate();
                // make sure the under construction block has not been migrated
                LocatedBlocks lbs = test.dfs.GetClient().GetLocatedBlocks(barFile.ToString(), BlockSize
                                                                          );
                Log.Info("Locations: " + lbs);
                IList <LocatedBlock> blks = lbs.GetLocatedBlocks();
                NUnit.Framework.Assert.AreEqual(1, blks.Count);
                NUnit.Framework.Assert.AreEqual(1, blks[0].GetLocations().Length);
                Banner("finish the migration, continue writing");
                // make sure the writing can continue
                @out.WriteBytes("world!");
                ((DFSOutputStream)@out.GetWrappedStream()).Hsync();
                IOUtils.Cleanup(Log, @out);
                lbs = test.dfs.GetClient().GetLocatedBlocks(barFile.ToString(), BlockSize);
                Log.Info("Locations: " + lbs);
                blks = lbs.GetLocatedBlocks();
                NUnit.Framework.Assert.AreEqual(1, blks.Count);
                NUnit.Framework.Assert.AreEqual(1, blks[0].GetLocations().Length);
                Banner("finish writing, starting reading");
                // check the content of /foo/bar
                FSDataInputStream @in = test.dfs.Open(barFile);
                byte[]            buf = new byte[13];
                // read from offset 1024
                @in.ReadFully(BlockSize, buf, 0, buf.Length);
                IOUtils.Cleanup(Log, @in);
                NUnit.Framework.Assert.AreEqual("hello, world!", Sharpen.Runtime.GetStringForBytes
                                                    (buf));
            }
            finally
            {
                test.ShutdownCluster();
            }
        }