Example #1
0
        public virtual void TestCredentialSuccessfulLifecycle()
        {
            outContent.Reset();
            string[] args1 = new string[] { "create", "credential1", "-value", "p@ssw0rd", "-provider"
                                            , jceksProvider };
            int             rc = 0;
            CredentialShell cs = new CredentialShell();

            cs.SetConf(new Configuration());
            rc = cs.Run(args1);
            Assert.Equal(outContent.ToString(), 0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "created."));
            outContent.Reset();
            string[] args2 = new string[] { "list", "-provider", jceksProvider };
            rc = cs.Run(args2);
            Assert.Equal(0, rc);
            Assert.True(outContent.ToString().Contains("credential1"));
            outContent.Reset();
            string[] args4 = new string[] { "delete", "credential1", "-f", "-provider", jceksProvider };
            rc = cs.Run(args4);
            Assert.Equal(0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "deleted."));
            outContent.Reset();
            string[] args5 = new string[] { "list", "-provider", jceksProvider };
            rc = cs.Run(args5);
            Assert.Equal(0, rc);
            NUnit.Framework.Assert.IsFalse(outContent.ToString(), outContent.ToString().Contains
                                               ("credential1"));
        }
Example #2
0
 public virtual void Setup()
 {
     errContent.Reset();
     initialStdErr = System.Console.Error;
     Runtime.SetErr(new TextWriter(errContent));
     conf = new Configuration();
 }
Example #3
0
        private void AssertOutputMatches(string @string)
        {
            string errOutput = new string(@out.ToByteArray(), Charsets.Utf8);
            string output    = new string(@out.ToByteArray(), Charsets.Utf8);

            if (!errOutput.Matches(@string) && !output.Matches(@string))
            {
                NUnit.Framework.Assert.Fail("Expected output to match '" + @string + "' but err_output was:\n"
                                            + errOutput + "\n and output was: \n" + output);
            }
            @out.Reset();
            err.Reset();
        }
Example #4
0
 /// <exception cref="System.IO.IOException"/>
 private void TestWrite(ExtendedBlock block, BlockConstructionStage stage, long newGS
                        , string description, bool eofExcepted)
 {
     sendBuf.Reset();
     recvBuf.Reset();
     WriteBlock(block, stage, newGS, DefaultChecksum);
     if (eofExcepted)
     {
         SendResponse(DataTransferProtos.Status.Error, null, null, recvOut);
         SendRecvData(description, true);
     }
     else
     {
         if (stage == BlockConstructionStage.PipelineCloseRecovery)
         {
             //ok finally write a block with 0 len
             SendResponse(DataTransferProtos.Status.Success, string.Empty, null, recvOut);
             SendRecvData(description, false);
         }
         else
         {
             WriteZeroLengthPacket(block, description);
         }
     }
 }
Example #5
0
        public virtual void TestRenameSnapshotCommandWithIllegalArguments()
        {
            ByteArrayOutputStream @out  = new ByteArrayOutputStream();
            TextWriter            psOut = new TextWriter(@out);

            Runtime.SetOut(psOut);
            Runtime.SetErr(psOut);
            FsShell shell = new FsShell();

            shell.SetConf(conf);
            string[] argv1 = new string[] { "-renameSnapshot", "/tmp", "s1" };
            int      val   = shell.Run(argv1);

            NUnit.Framework.Assert.IsTrue(val == -1);
            NUnit.Framework.Assert.IsTrue(@out.ToString().Contains(argv1[0] + ": Incorrect number of arguments."
                                                                   ));
            @out.Reset();
            string[] argv2 = new string[] { "-renameSnapshot", "/tmp", "s1", "s2", "s3" };
            val = shell.Run(argv2);
            NUnit.Framework.Assert.IsTrue(val == -1);
            NUnit.Framework.Assert.IsTrue(@out.ToString().Contains(argv2[0] + ": Incorrect number of arguments."
                                                                   ));
            psOut.Close();
            @out.Close();
        }
Example #6
0
        /// <summary>print a job list</summary>
        /// <exception cref="System.Exception"/>
        protected internal virtual void TestAllJobList(string jobId, Configuration conf)
        {
            ByteArrayOutputStream @out = new ByteArrayOutputStream();
            // bad options
            int exitCode = RunTool(conf, CreateJobClient(), new string[] { "-list", "alldata" }, @out);

            NUnit.Framework.Assert.AreEqual("Exit code", -1, exitCode);
            exitCode = RunTool(conf, CreateJobClient(), new string[] { "-list", "all" }, @out
                               );
            // all jobs
            NUnit.Framework.Assert.AreEqual("Exit code", 0, exitCode);
            BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream
                                                                             (@out.ToByteArray())));
            string line;
            int    counter = 0;

            while ((line = br.ReadLine()) != null)
            {
                Log.Info("line = " + line);
                if (line.Contains(jobId))
                {
                    counter++;
                }
            }
            NUnit.Framework.Assert.AreEqual(1, counter);
            @out.Reset();
        }
Example #7
0
 public override void Clear()
 {
     if (null != inbuf)
     {
         inbuf.ResetStream();
     }
     outbuf.Reset();
     outfbuf = new DataOutputStream(outbuf);
 }
Example #8
0
        /// <exception cref="System.Exception"/>
        private int RunTool(params string[] args)
        {
            errOutBytes.Reset();
            Log.Info("Running: DFSHAAdmin " + Joiner.On(" ").Join(args));
            int ret = tool.Run(args);

            errOutput = new string(errOutBytes.ToByteArray(), Charsets.Utf8);
            Log.Info("Output:\n" + errOutput);
            return(ret);
        }
Example #9
0
        /// <exception cref="System.Exception"/>
        private void TestError(string[] args, string template, ByteArrayOutputStream data
                               , int resultCode)
        {
            int actualResultCode = rmAdminCLI.Run(args);

            NUnit.Framework.Assert.AreEqual("Expected result code: " + resultCode + ", actual result code is: "
                                            + actualResultCode, resultCode, actualResultCode);
            NUnit.Framework.Assert.IsTrue(string.Format("Expected error message: %n" + template
                                                        + " is not included in messages: %n" + data.ToString()), data.ToString().Contains
                                              (template));
            data.Reset();
        }
Example #10
0
 public byte[] GetDataAndReset()
 {
     try
     {
         byte[] data;
         bos.Flush();
         data = bos.ToByteArray();
         bos.Reset();
         return(data);
     }
     catch (System.Exception ex)
     {
         throw new IOException(ex.Message);
     }
 }
Example #11
0
        // COPY: Copied from libcore.net.UriCodec
        /// <param name="convertPlus">true to convert '+' to ' '.</param>
        public static string Decode(string s, bool convertPlus, Encoding charset)
        {
            if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1))
            {
                return(s);
            }
            StringBuilder         result = new StringBuilder(s.Length);
            ByteArrayOutputStream @out   = new ByteArrayOutputStream();

            for (int i = 0; i < s.Length;)
            {
                char c = s[i];
                if (c == '%')
                {
                    do
                    {
                        if (i + 2 >= s.Length)
                        {
                            throw new ArgumentException("Incomplete % sequence at: " + i);
                        }
                        int d1 = HexToInt(s[i + 1]);
                        int d2 = HexToInt(s[i + 2]);
                        if (d1 == -1 || d2 == -1)
                        {
                            throw new ArgumentException("Invalid % sequence " + Sharpen.Runtime.Substring(s,
                                                                                                          i, i + 3) + " at " + i);
                        }
                        @out.Write(unchecked ((byte)((d1 << 4) + d2)));
                        i += 3;
                    }while (i < s.Length && s[i] == '%');
                    var outBytes = @out.ToByteArray();
                    result.Append(charset.GetString(outBytes, 0, outBytes.Length));
                    @out.Reset();
                }
                else
                {
                    if (convertPlus && c == '+')
                    {
                        c = ' ';
                    }
                    result.Append(c);
                    i++;
                }
            }
            return(result.ToString());
        }
Example #12
0
		public override void Write(int b)
		{
			if (b == '\n')
			{
				// synchronize on "this" first to avoid potential deadlock
				lock (this)
				{
					lock (LogOut)
					{
						// construct prefix for log messages:
						Buffer.Length = 0;
						Buffer.Append((DateTime.Now).ToString()); // date/time stamp...
						Buffer.Append(':');
						Buffer.Append(Name); // ...log name...
						Buffer.Append(':');
						Buffer.Append(Thread.CurrentThread.Name);
						Buffer.Append(':'); // ...and thread name

						try
						{
							// write prefix through to underlying byte stream
							LogWriter.Write(Buffer.ToString());
							LogWriter.Flush();

							// finally, write the already converted bytes of
							// the log message
							BufOut.WriteTo(LogOut);
							LogOut.Write(b);
							LogOut.Flush();
						}
						catch (IOException)
						{
							SetError();
						}
						finally
						{
							BufOut.Reset();
						}
					}
				}
			}
			else
			{
				base.Write(b);
			}
		}
Example #13
0
        public virtual void TestWriteTo()
        {
            FSDataInputStream     fsdin = new FSDataInputStream(new MockFSInputStream());
            ByteArrayOutputStream os    = new ByteArrayOutputStream();

            // new int[]{s_1, c_1, s_2, c_2, ..., s_n, c_n} means to test
            // reading c_i bytes starting at s_i
            int[] pairs = new int[] { 0, 10000, 50, 100, 50, 6000, 1000, 2000, 0, 1, 0, 0, 5000
                                      , 0 };
            NUnit.Framework.Assert.IsTrue("Pairs array must be even", pairs.Length % 2 == 0);
            for (int i = 0; i < pairs.Length; i += 2)
            {
                StreamFile.CopyFromOffset(fsdin, os, pairs[i], pairs[i + 1]);
                Assert.AssertArrayEquals("Reading " + pairs[i + 1] + " bytes from offset " + pairs
                                         [i], GetOutputArray(pairs[i], pairs[i + 1]), os.ToByteArray());
                os.Reset();
            }
        }
Example #14
0
        public virtual void TestRMHAErrorUsage()
        {
            ByteArrayOutputStream errOutBytes = new ByteArrayOutputStream();

            rmAdminCLIWithHAEnabled.SetErrOut(new TextWriter(errOutBytes));
            try
            {
                string[] args = new string[] { "-failover" };
                NUnit.Framework.Assert.AreEqual(-1, rmAdminCLIWithHAEnabled.Run(args));
                string errOut = new string(errOutBytes.ToByteArray(), Charsets.Utf8);
                errOutBytes.Reset();
                NUnit.Framework.Assert.IsTrue(errOut.Contains("Usage: rmadmin"));
            }
            finally
            {
                rmAdminCLIWithHAEnabled.SetErrOut(System.Console.Error);
            }
        }
Example #15
0
        public virtual void Setup()
        {
            outContent.Reset();
            errContent.Reset();
            FilePath tmpDir = new FilePath(Runtime.GetProperty("test.build.data", "target"),
                                           UUID.RandomUUID().ToString());

            if (!tmpDir.Mkdirs())
            {
                throw new IOException("Unable to create " + tmpDir);
            }
            Path jksPath = new Path(tmpDir.ToString(), "keystore.jceks");

            jceksProvider = "jceks://file" + jksPath.ToUri();
            initialStdOut = System.Console.Out;
            initialStdErr = System.Console.Error;
            Runtime.SetOut(new TextWriter(outContent));
            Runtime.SetErr(new TextWriter(errContent));
        }
Example #16
0
 public virtual void TestSendPartialData()
 {
     FSDataInputStream     @in = new FSDataInputStream(new MockFSInputStream());
     ByteArrayOutputStream os  = new ByteArrayOutputStream();
     {
         // test if multiple ranges, then 416
         IList <InclusiveByteRange> ranges   = StrToRanges("0-,10-300", 500);
         HttpServletResponse        response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
         StreamFile.SendPartialData(@in, os, response, 500, ranges);
         // Multiple ranges should result in a 416 error
         Org.Mockito.Mockito.Verify(response).SetStatus(416);
     }
     {
         // test if no ranges, then 416
         os.Reset();
         HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
         StreamFile.SendPartialData(@in, os, response, 500, null);
         // No ranges should result in a 416 error
         Org.Mockito.Mockito.Verify(response).SetStatus(416);
     }
     {
         // test if invalid single range (out of bounds), then 416
         IList <InclusiveByteRange> ranges   = StrToRanges("600-800", 500);
         HttpServletResponse        response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
         StreamFile.SendPartialData(@in, os, response, 500, ranges);
         // Single (but invalid) range should result in a 416
         Org.Mockito.Mockito.Verify(response).SetStatus(416);
     }
     {
         // test if one (valid) range, then 206
         IList <InclusiveByteRange> ranges   = StrToRanges("100-300", 500);
         HttpServletResponse        response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
         StreamFile.SendPartialData(@in, os, response, 500, ranges);
         // Single (valid) range should result in a 206
         Org.Mockito.Mockito.Verify(response).SetStatus(206);
         Assert.AssertArrayEquals("Byte range from 100-300", GetOutputArray(100, 201), os.
                                  ToByteArray());
     }
 }
Example #17
0
 /// <summary>Read a single byte from the stream.</summary>
 /// <exception cref="System.IO.IOException"/>
 public override int Read()
 {
     if (pos < buffer.Length)
     {
         return(buffer[pos++]);
     }
     if (!fileReader.HasNext())
     {
         return(-1);
     }
     writer.Write(fileReader.Next(), encoder);
     encoder.Flush();
     if (!fileReader.HasNext())
     {
         // Write a new line after the last Avro record.
         output.Write(Runtime.GetBytesForString(Runtime.GetProperty("line.separator"
                                                                    ), Charsets.Utf8));
         output.Flush();
     }
     pos    = 0;
     buffer = output.ToByteArray();
     output.Reset();
     return(Read());
 }