コード例 #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestJournal()
        {
            MetricsRecordBuilder metrics = MetricsAsserts.GetMetrics(journal.GetMetricsForTests
                                                                         ().GetName());

            MetricsAsserts.AssertCounter("BatchesWritten", 0L, metrics);
            MetricsAsserts.AssertCounter("BatchesWrittenWhileLagging", 0L, metrics);
            MetricsAsserts.AssertGauge("CurrentLagTxns", 0L, metrics);
            IPCLoggerChannel ch = new IPCLoggerChannel(conf, FakeNsinfo, journalId, jn.GetBoundIpcAddress
                                                           ());

            ch.NewEpoch(1).Get();
            ch.SetEpoch(1);
            ch.StartLogSegment(1, NameNodeLayoutVersion.CurrentLayoutVersion).Get();
            ch.SendEdits(1L, 1, 1, Sharpen.Runtime.GetBytesForString("hello", Charsets.Utf8))
            .Get();
            metrics = MetricsAsserts.GetMetrics(journal.GetMetricsForTests().GetName());
            MetricsAsserts.AssertCounter("BatchesWritten", 1L, metrics);
            MetricsAsserts.AssertCounter("BatchesWrittenWhileLagging", 0L, metrics);
            MetricsAsserts.AssertGauge("CurrentLagTxns", 0L, metrics);
            ch.SetCommittedTxId(100L);
            ch.SendEdits(1L, 2, 1, Sharpen.Runtime.GetBytesForString("goodbye", Charsets.Utf8
                                                                     )).Get();
            metrics = MetricsAsserts.GetMetrics(journal.GetMetricsForTests().GetName());
            MetricsAsserts.AssertCounter("BatchesWritten", 2L, metrics);
            MetricsAsserts.AssertCounter("BatchesWrittenWhileLagging", 1L, metrics);
            MetricsAsserts.AssertGauge("CurrentLagTxns", 98L, metrics);
        }
コード例 #2
0
        public virtual void Setup()
        {
            FilePath editsDir = new FilePath(MiniDFSCluster.GetBaseDirectory() + FilePath.separator
                                             + "TestJournalNode");

            FileUtil.FullyDelete(editsDir);
            conf.Set(DFSConfigKeys.DfsJournalnodeEditsDirKey, editsDir.GetAbsolutePath());
            conf.Set(DFSConfigKeys.DfsJournalnodeRpcAddressKey, "0.0.0.0:0");
            jn = new JournalNode();
            jn.SetConf(conf);
            jn.Start();
            journalId = "test-journalid-" + GenericTestUtils.UniqueSequenceId();
            journal   = jn.GetOrCreateJournal(journalId);
            journal.Format(FakeNsinfo);
            ch = new IPCLoggerChannel(conf, FakeNsinfo, journalId, jn.GetBoundIpcAddress());
        }
コード例 #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestHttpServer()
        {
            string urlRoot = jn.GetHttpServerURI();
            // Check default servlets.
            string pageContents = DFSTestUtil.UrlGet(new Uri(urlRoot + "/jmx"));

            NUnit.Framework.Assert.IsTrue("Bad contents: " + pageContents, pageContents.Contains
                                              ("Hadoop:service=JournalNode,name=JvmMetrics"));
            // Create some edits on server side
            byte[]           EditsData = QJMTestUtil.CreateTxnData(1, 3);
            IPCLoggerChannel ch        = new IPCLoggerChannel(conf, FakeNsinfo, journalId, jn.GetBoundIpcAddress
                                                                  ());

            ch.NewEpoch(1).Get();
            ch.SetEpoch(1);
            ch.StartLogSegment(1, NameNodeLayoutVersion.CurrentLayoutVersion).Get();
            ch.SendEdits(1L, 1, 3, EditsData).Get();
            ch.FinalizeLogSegment(1, 3).Get();
            // Attempt to retrieve via HTTP, ensure we get the data back
            // including the header we expected
            byte[] retrievedViaHttp = DFSTestUtil.UrlGetBytes(new Uri(urlRoot + "/getJournal?segmentTxId=1&jid="
                                                                      + journalId));
            byte[] expected = Bytes.Concat(Ints.ToByteArray(HdfsConstants.NamenodeLayoutVersion
                                                            ), (new byte[] { 0, 0, 0, 0 }), EditsData);
            // layout flags section
            Assert.AssertArrayEquals(expected, retrievedViaHttp);
            // Attempt to fetch a non-existent file, check that we get an
            // error status code
            Uri badUrl = new Uri(urlRoot + "/getJournal?segmentTxId=12345&jid=" + journalId);
            HttpURLConnection connection = (HttpURLConnection)badUrl.OpenConnection();

            try
            {
                NUnit.Framework.Assert.AreEqual(404, connection.GetResponseCode());
            }
            finally
            {
                connection.Disconnect();
            }
        }