Esempio n. 1
0
        /// <summary>Expire the ZK session of the given service.</summary>
        /// <remarks>
        /// Expire the ZK session of the given service. This requires
        /// (and asserts) that the given service be the current active.
        /// </remarks>
        /// <exception cref="Org.Apache.Zookeeper.KeeperException.NoNodeException">if no service holds the lock
        ///     </exception>
        public virtual void ExpireActiveLockHolder(int idx)
        {
            Stat stat = new Stat();

            byte[] data = zks.GetZKDatabase().GetData(MiniZKFCCluster.DummyZKFC.LockZnode, stat
                                                      , null);
            Assert.AssertArrayEquals(Ints.ToByteArray(svcs[idx].index), data);
            long session = stat.GetEphemeralOwner();

            Log.Info("Expiring svc " + idx + "'s zookeeper session " + session);
            zks.CloseSession(session);
        }
 /// <exception cref="System.Exception"/>
 public override void SetUp()
 {
     base.SetUp();
     zkServer = GetServer(serverFactory);
     for (int i = 0; i < NumElectors; i++)
     {
         cbs[i] = Org.Mockito.Mockito.Mock <ActiveStandbyElector.ActiveStandbyElectorCallback
                                            >();
         appDatas[i] = Ints.ToByteArray(i);
         electors[i] = new ActiveStandbyElector(hostPort, 5000, ParentDir, ZooDefs.Ids.OpenAclUnsafe
                                                , Collections.EmptyList <ZKUtil.ZKAuthInfo>(), cbs[i], CommonConfigurationKeys.HaFcElectorZkOpRetriesDefault
                                                );
     }
 }
Esempio n. 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();
            }
        }
Esempio n. 4
0
 protected internal override byte[] TargetToData(HAServiceTarget target)
 {
     return(Ints.ToByteArray(((DummyHAService)target).index));
 }
Esempio n. 5
0
        /// <summary>Wait for the given HA service to become the active lock holder.</summary>
        /// <remarks>
        /// Wait for the given HA service to become the active lock holder.
        /// If the passed svc is null, waits for there to be no active
        /// lock holder.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void WaitForActiveLockHolder(int idx)
        {
            DummyHAService svc = idx == null ? null : svcs[idx];

            ActiveStandbyElectorTestUtil.WaitForActiveLockData(ctx, zks, MiniZKFCCluster.DummyZKFC
                                                               .ScopedParentZnode, (idx == null) ? null : Ints.ToByteArray(svc.index));
        }