/// <summary> /// Insert a Mockito spy object between the given DataNode and /// the given NameNode. /// </summary> /// <remarks> /// Insert a Mockito spy object between the given DataNode and /// the given NameNode. This can be used to delay or wait for /// RPC calls on the datanode->NN path. /// </remarks> public static DatanodeProtocolClientSideTranslatorPB SpyOnBposToNN(DataNode dn, NameNode nn) { string bpid = nn.GetNamesystem().GetBlockPoolId(); BPOfferService bpos = null; foreach (BPOfferService thisBpos in dn.GetAllBpOs()) { if (thisBpos.GetBlockPoolId().Equals(bpid)) { bpos = thisBpos; break; } } Preconditions.CheckArgument(bpos != null, "No such bpid: %s", bpid); BPServiceActor bpsa = null; foreach (BPServiceActor thisBpsa in bpos.GetBPServiceActors()) { if (thisBpsa.GetNNSocketAddress().Equals(nn.GetServiceRpcAddress())) { bpsa = thisBpsa; break; } } Preconditions.CheckArgument(bpsa != null, "No service actor to NN at %s", nn.GetServiceRpcAddress ()); DatanodeProtocolClientSideTranslatorPB origNN = bpsa.GetNameNodeProxy(); DatanodeProtocolClientSideTranslatorPB spy = Org.Mockito.Mockito.Spy(origNN); bpsa.SetNameNode(spy); return(spy); }
public virtual void TestIgnoreDeletionsFromNonActive() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); // Ask to invalidate FAKE_BLOCK when block report hits the // standby Org.Mockito.Mockito.DoReturn(new BlockCommand(DatanodeProtocol.DnaInvalidate, FakeBpid , new Block[] { FakeBlock.GetLocalBlock() })).When(mockNN2).BlockReport(Org.Mockito.Mockito .AnyObject <DatanodeRegistration>(), Org.Mockito.Mockito.Eq(FakeBpid), Org.Mockito.Mockito .AnyObject <StorageBlockReport[]>(), Org.Mockito.Mockito.AnyObject <BlockReportContext >()); bpos.Start(); try { WaitForInitialization(bpos); // Should get block reports from both NNs WaitForBlockReport(mockNN1); WaitForBlockReport(mockNN2); } finally { bpos.Stop(); } // Should ignore the delete command from the standby Org.Mockito.Mockito.Verify(mockFSDataset, Org.Mockito.Mockito.Never()).Invalidate (Org.Mockito.Mockito.Eq(FakeBpid), (Block[])Org.Mockito.Mockito.AnyObject()); }
public virtual void TestBasicFunctionality() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForInitialization(bpos); // The DN should have register to both NNs. Org.Mockito.Mockito.Verify(mockNN1).RegisterDatanode(Org.Mockito.Mockito.Any <DatanodeRegistration >()); Org.Mockito.Mockito.Verify(mockNN2).RegisterDatanode(Org.Mockito.Mockito.Any <DatanodeRegistration >()); // Should get block reports from both NNs WaitForBlockReport(mockNN1); WaitForBlockReport(mockNN2); // When we receive a block, it should report it to both NNs bpos.NotifyNamenodeReceivedBlock(FakeBlock, string.Empty, string.Empty); ReceivedDeletedBlockInfo[] ret = WaitForBlockReceived(FakeBlock, mockNN1); NUnit.Framework.Assert.AreEqual(1, ret.Length); NUnit.Framework.Assert.AreEqual(FakeBlock.GetLocalBlock(), ret[0].GetBlock()); ret = WaitForBlockReceived(FakeBlock, mockNN2); NUnit.Framework.Assert.AreEqual(1, ret.Length); NUnit.Framework.Assert.AreEqual(FakeBlock.GetLocalBlock(), ret[0].GetBlock()); } finally { bpos.Stop(); } }
public virtual void SetUp() { mockDnConf = Org.Mockito.Mockito.Mock <DNConf>(); Org.Mockito.Mockito.DoReturn(VersionInfo.GetVersion()).When(mockDnConf).GetMinimumNameNodeVersion (); DataNode mockDN = Org.Mockito.Mockito.Mock <DataNode>(); Org.Mockito.Mockito.DoReturn(true).When(mockDN).ShouldRun(); Org.Mockito.Mockito.DoReturn(mockDnConf).When(mockDN).GetDnConf(); BPOfferService mockBPOS = Org.Mockito.Mockito.Mock <BPOfferService>(); Org.Mockito.Mockito.DoReturn(mockDN).When(mockBPOS).GetDataNode(); actor = new BPServiceActor(InvalidAddr, mockBPOS); fakeNsInfo = Org.Mockito.Mockito.Mock <NamespaceInfo>(); // Return a a good software version. Org.Mockito.Mockito.DoReturn(VersionInfo.GetVersion()).When(fakeNsInfo).GetSoftwareVersion (); // Return a good layout version for now. Org.Mockito.Mockito.DoReturn(HdfsConstants.NamenodeLayoutVersion).When(fakeNsInfo ).GetLayoutVersion(); DatanodeProtocolClientSideTranslatorPB fakeDnProt = Org.Mockito.Mockito.Mock <DatanodeProtocolClientSideTranslatorPB >(); Org.Mockito.Mockito.When(fakeDnProt.VersionRequest()).ThenReturn(fakeNsInfo); actor.SetNameNode(fakeDnProt); }
internal virtual void Remove(BPOfferService t) { lock (this) { offerServices.Remove(t); if (t.HasBlockPoolId()) { // It's possible that the block pool never successfully registered // with any NN, so it was never added it to this map Sharpen.Collections.Remove(bpByBlockPoolId, t.GetBlockPoolId()); } bool removed = false; for (IEnumerator <BPOfferService> it = bpByNameserviceId.Values.GetEnumerator(); it .HasNext() && !removed;) { BPOfferService bpos = it.Next(); if (bpos == t) { it.Remove(); Log.Info("Removed " + bpos); removed = true; } } if (!removed) { Log.Warn("Couldn't remove BPOS " + t + " from bpByNameserviceId map"); } } }
public virtual void TestTrySendErrorReportWhenNNThrowsIOException() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForInitialization(bpos); // Should start with neither NN as active. NUnit.Framework.Assert.IsNull(bpos.GetActiveNN()); // Have NN1 claim active at txid 1 mockHaStatuses[0] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 1); bpos.TriggerHeartbeatForTests(); // Now mockNN1 is acting like active namenode and mockNN2 as Standby NUnit.Framework.Assert.AreSame(mockNN1, bpos.GetActiveNN()); Org.Mockito.Mockito.DoAnswer(new _Answer_602(this)).When(mockNN1).ErrorReport(Org.Mockito.Mockito .Any <DatanodeRegistration>(), Org.Mockito.Mockito.AnyInt(), Org.Mockito.Mockito. AnyString()); // Throw an IOException when this function is first called which will // in turn add that errorReport back to the bpThreadQueue and let it // process the next time. string errorString = "Can't send invalid block " + FakeBlock; bpos.TrySendErrorReport(DatanodeProtocol.InvalidBlock, errorString); Sharpen.Thread.Sleep(10000); NUnit.Framework.Assert.IsTrue("Active namenode didn't add the report back to the queue " + "when errorReport threw IOException", secondCallTime != 0); } finally { bpos.Stop(); } }
private static IPEndPoint GetNNSocketAddress(BPOfferService bpos) { IList <BPServiceActor> actors = bpos.GetBPServiceActors(); NUnit.Framework.Assert.AreEqual(1, actors.Count); return(actors[0].GetNNSocketAddress()); }
/// <summary>Returns the array of BPOfferService objects.</summary> /// <remarks> /// Returns the array of BPOfferService objects. /// Caution: The BPOfferService returned could be shutdown any time. /// </remarks> internal virtual BPOfferService[] GetAllNamenodeThreads() { lock (this) { BPOfferService[] bposArray = new BPOfferService[offerServices.Count]; return(Sharpen.Collections.ToArray(offerServices, bposArray)); } }
public virtual void StartCluster() { conf = new HdfsConfiguration(); cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(DnCount).Build(); fs = cluster.GetFileSystem(); singletonNn = cluster.GetNameNode(); singletonDn = cluster.GetDataNodes()[0]; bpos = singletonDn.GetAllBpOs()[0]; actor = bpos.GetBPServiceActors()[0]; storageUuid = singletonDn.GetFSDataset().GetVolumes()[0].GetStorageID(); }
internal virtual void AddBlockPool(BPOfferService bpos) { lock (this) { Preconditions.CheckArgument(offerServices.Contains(bpos), "Unknown BPOS: %s", bpos ); if (bpos.GetBlockPoolId() == null) { throw new ArgumentException("Null blockpool id"); } bpByBlockPoolId[bpos.GetBlockPoolId()] = bpos; } }
public virtual void TestFedSingleNN() { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NameNodePort(9927).Build (); try { NameNode nn1 = cluster.GetNameNode(); NUnit.Framework.Assert.IsNotNull("cannot create nn1", nn1); string bpid1 = FSImageTestUtil.GetFSImage(nn1).GetBlockPoolID(); string cid1 = FSImageTestUtil.GetFSImage(nn1).GetClusterID(); int lv1 = FSImageTestUtil.GetFSImage(nn1).GetLayoutVersion(); Log.Info("nn1: lv=" + lv1 + ";cid=" + cid1 + ";bpid=" + bpid1 + ";uri=" + nn1.GetNameNodeAddress ()); // check number of vlumes in fsdataset DataNode dn = cluster.GetDataNodes()[0]; IDictionary <string, object> volInfos = dn.data.GetVolumeInfoMap(); NUnit.Framework.Assert.IsTrue("No volumes in the fsdataset", volInfos.Count > 0); int i = 0; foreach (KeyValuePair <string, object> e in volInfos) { Log.Info("vol " + i++ + ") " + e.Key + ": " + e.Value); } // number of volumes should be 2 - [data1, data2] NUnit.Framework.Assert.AreEqual("number of volumes is wrong", 2, volInfos.Count); foreach (BPOfferService bpos in dn.GetAllBpOs()) { Log.Info("reg: bpid=" + "; name=" + bpos.bpRegistration + "; sid=" + bpos.bpRegistration .GetDatanodeUuid() + "; nna=" + GetNNSocketAddress(bpos)); } // try block report BPOfferService bpos1 = dn.GetAllBpOs()[0]; bpos1.TriggerBlockReportForTests(); NUnit.Framework.Assert.AreEqual("wrong nn address", GetNNSocketAddress(bpos1), nn1 .GetNameNodeAddress()); NUnit.Framework.Assert.AreEqual("wrong bpid", bpos1.GetBlockPoolId(), bpid1); NUnit.Framework.Assert.AreEqual("wrong cid", dn.GetClusterId(), cid1); cluster.Shutdown(); // Ensure all the BPOfferService threads are shutdown NUnit.Framework.Assert.AreEqual(0, dn.GetAllBpOs().Length); cluster = null; } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestNNsFromDifferentClusters() { Org.Mockito.Mockito.DoReturn(new NamespaceInfo(1, "fake foreign cluster", FakeBpid , 0)).When(mockNN1).VersionRequest(); BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForOneToFail(bpos); } finally { bpos.Stop(); } }
public virtual void TestReportBadBlocksWhenNNThrowsStandbyException() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForInitialization(bpos); // Should start with neither NN as active. NUnit.Framework.Assert.IsNull(bpos.GetActiveNN()); // Have NN1 claim active at txid 1 mockHaStatuses[0] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 1); bpos.TriggerHeartbeatForTests(); // Now mockNN1 is acting like active namenode and mockNN2 as Standby NUnit.Framework.Assert.AreSame(mockNN1, bpos.GetActiveNN()); // Return nothing when active Active Namenode calls reportBadBlocks Org.Mockito.Mockito.DoNothing().When(mockNN1).ReportBadBlocks(Org.Mockito.Mockito .Any <LocatedBlock[]>()); RemoteException re = new RemoteException(typeof(StandbyException).FullName, "Operation category WRITE is not supported in state " + "standby", RpcHeaderProtos.RpcResponseHeaderProto.RpcErrorCodeProto.ErrorApplication ); // Return StandbyException wrapped in RemoteException when Standby NN // calls reportBadBlocks Org.Mockito.Mockito.DoThrow(re).When(mockNN2).ReportBadBlocks(Org.Mockito.Mockito .Any <LocatedBlock[]>()); bpos.ReportBadBlocks(FakeBlock, mockFSDataset.GetVolume(FakeBlock).GetStorageID() , mockFSDataset.GetVolume(FakeBlock).GetStorageType()); // Send heartbeat so that the BpServiceActor can report bad block to // namenode bpos.TriggerHeartbeatForTests(); Org.Mockito.Mockito.Verify(mockNN2, Org.Mockito.Mockito.Times(1)).ReportBadBlocks (Org.Mockito.Mockito.Any <LocatedBlock[]>()); // Trigger another heartbeat, this will send reportBadBlock again if it // is present in the queue. bpos.TriggerHeartbeatForTests(); Org.Mockito.Mockito.Verify(mockNN2, Org.Mockito.Mockito.Times(1)).ReportBadBlocks (Org.Mockito.Mockito.Any <LocatedBlock[]>()); } finally { bpos.Stop(); } }
public virtual void TestPickActiveNameNode() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForInitialization(bpos); // Should start with neither NN as active. NUnit.Framework.Assert.IsNull(bpos.GetActiveNN()); // Have NN1 claim active at txid 1 mockHaStatuses[0] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 1); bpos.TriggerHeartbeatForTests(); NUnit.Framework.Assert.AreSame(mockNN1, bpos.GetActiveNN()); // NN2 claims active at a higher txid mockHaStatuses[1] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 2); bpos.TriggerHeartbeatForTests(); NUnit.Framework.Assert.AreSame(mockNN2, bpos.GetActiveNN()); // Even after another heartbeat from the first NN, it should // think NN2 is active, since it claimed a higher txid bpos.TriggerHeartbeatForTests(); NUnit.Framework.Assert.AreSame(mockNN2, bpos.GetActiveNN()); // Even if NN2 goes to standby, DN shouldn't reset to talking to NN1, // because NN1's txid is lower than the last active txid. Instead, // it should consider neither active. mockHaStatuses[1] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Standby , 2); bpos.TriggerHeartbeatForTests(); NUnit.Framework.Assert.IsNull(bpos.GetActiveNN()); // Now if NN1 goes back to a higher txid, it should be considered active mockHaStatuses[0] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 3); bpos.TriggerHeartbeatForTests(); NUnit.Framework.Assert.AreSame(mockNN1, bpos.GetActiveNN()); } finally { bpos.Stop(); } }
protected internal override BPOfferService CreateBPOS(IList <IPEndPoint> nnAddrs) { int idx = this._enclosing.mockIdx++; this._enclosing.DoLog("create #" + idx); BPOfferService bpos = Org.Mockito.Mockito.Mock <BPOfferService>(); Org.Mockito.Mockito.DoReturn("Mock BPOS #" + idx).When(bpos).ToString(); // Log refreshes try { Org.Mockito.Mockito.DoAnswer(new _Answer_62(this, idx)).When(bpos).RefreshNNList( Org.Mockito.Mockito.Any <AList <IPEndPoint> >()); } catch (IOException e) { throw new RuntimeException(e); } // Log stops Org.Mockito.Mockito.DoAnswer(new _Answer_75(this, idx, bpos)).When(bpos).Stop(); return(bpos); }
public virtual void TestReportBadBlockWhenStandbyNNTimesOut() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForInitialization(bpos); // Should start with neither NN as active. NUnit.Framework.Assert.IsNull(bpos.GetActiveNN()); // Have NN1 claim active at txid 1 mockHaStatuses[0] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 1); bpos.TriggerHeartbeatForTests(); // Now mockNN1 is acting like active namenode and mockNN2 as Standby NUnit.Framework.Assert.AreSame(mockNN1, bpos.GetActiveNN()); Org.Mockito.Mockito.DoAnswer(new TestBPOfferService.BPOfferServiceSynchronousCallAnswer (this, 0)).When(mockNN1).ReportBadBlocks(Org.Mockito.Mockito.Any <LocatedBlock[]> ()); Org.Mockito.Mockito.DoAnswer(new TestBPOfferService.BPOfferServiceSynchronousCallAnswer (this, 1)).When(mockNN2).ReportBadBlocks(Org.Mockito.Mockito.Any <LocatedBlock[]> ()); bpos.ReportBadBlocks(FakeBlock, mockFSDataset.GetVolume(FakeBlock).GetStorageID() , mockFSDataset.GetVolume(FakeBlock).GetStorageType()); bpos.ReportBadBlocks(FakeBlock, mockFSDataset.GetVolume(FakeBlock).GetStorageID() , mockFSDataset.GetVolume(FakeBlock).GetStorageType()); Sharpen.Thread.Sleep(10000); long difference = secondCallTime - firstCallTime; NUnit.Framework.Assert.IsTrue("Active namenode reportBadBlock processing should be " + "independent of standby namenode reportBadBlock processing ", difference < 5000 ); } finally { bpos.Stop(); } }
public virtual void TestBPInitErrorHandling() { DataNode mockDn = Org.Mockito.Mockito.Mock <DataNode>(); Org.Mockito.Mockito.DoReturn(true).When(mockDn).ShouldRun(); Configuration conf = new Configuration(); FilePath dnDataDir = new FilePath(new FilePath(TestBuildData, "testBPInitErrorHandling" ), "data"); conf.Set(DFSConfigKeys.DfsDatanodeDataDirKey, dnDataDir.ToURI().ToString()); Org.Mockito.Mockito.DoReturn(conf).When(mockDn).GetConf(); Org.Mockito.Mockito.DoReturn(new DNConf(conf)).When(mockDn).GetDnConf(); Org.Mockito.Mockito.DoReturn(DataNodeMetrics.Create(conf, "fake dn")).When(mockDn ).GetMetrics(); AtomicInteger count = new AtomicInteger(); Org.Mockito.Mockito.DoAnswer(new _Answer_328(this, count, mockDn)).When(mockDn).InitBlockPool (Org.Mockito.Mockito.Any <BPOfferService>()); // The initBlockPool is called again. Now mock init is done. BPOfferService bpos = SetupBPOSForNNs(mockDn, mockNN1, mockNN2); IList <BPServiceActor> actors = bpos.GetBPServiceActors(); NUnit.Framework.Assert.AreEqual(2, actors.Count); bpos.Start(); try { WaitForInitialization(bpos); // even if one of the actor initialization fails, the other one will be // finish block report. WaitForBlockReport(mockNN1, mockNN2); } finally { bpos.Stop(); } }
public virtual void TestTrySendErrorReportWhenStandbyNNTimesOut() { BPOfferService bpos = SetupBPOSForNNs(mockNN1, mockNN2); bpos.Start(); try { WaitForInitialization(bpos); // Should start with neither NN as active. NUnit.Framework.Assert.IsNull(bpos.GetActiveNN()); // Have NN1 claim active at txid 1 mockHaStatuses[0] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.Active , 1); bpos.TriggerHeartbeatForTests(); // Now mockNN1 is acting like active namenode and mockNN2 as Standby NUnit.Framework.Assert.AreSame(mockNN1, bpos.GetActiveNN()); Org.Mockito.Mockito.DoAnswer(new TestBPOfferService.BPOfferServiceSynchronousCallAnswer (this, 0)).When(mockNN1).ErrorReport(Org.Mockito.Mockito.Any <DatanodeRegistration >(), Org.Mockito.Mockito.AnyInt(), Org.Mockito.Mockito.AnyString()); Org.Mockito.Mockito.DoAnswer(new TestBPOfferService.BPOfferServiceSynchronousCallAnswer (this, 1)).When(mockNN2).ErrorReport(Org.Mockito.Mockito.Any <DatanodeRegistration >(), Org.Mockito.Mockito.AnyInt(), Org.Mockito.Mockito.AnyString()); string errorString = "Can't send invalid block " + FakeBlock; bpos.TrySendErrorReport(DatanodeProtocol.InvalidBlock, errorString); bpos.TrySendErrorReport(DatanodeProtocol.InvalidBlock, errorString); Sharpen.Thread.Sleep(10000); long difference = secondCallTime - firstCallTime; NUnit.Framework.Assert.IsTrue("Active namenode trySendErrorReport processing " + "should be independent of standby namenode trySendErrorReport" + " processing ", difference < 5000); } finally { bpos.Stop(); } }
public virtual void Test2NNRegistration() { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleFederatedTopology(2)).Build(); try { cluster.WaitActive(); NameNode nn1 = cluster.GetNameNode(0); NameNode nn2 = cluster.GetNameNode(1); NUnit.Framework.Assert.IsNotNull("cannot create nn1", nn1); NUnit.Framework.Assert.IsNotNull("cannot create nn2", nn2); string bpid1 = FSImageTestUtil.GetFSImage(nn1).GetBlockPoolID(); string bpid2 = FSImageTestUtil.GetFSImage(nn2).GetBlockPoolID(); string cid1 = FSImageTestUtil.GetFSImage(nn1).GetClusterID(); string cid2 = FSImageTestUtil.GetFSImage(nn2).GetClusterID(); int lv1 = FSImageTestUtil.GetFSImage(nn1).GetLayoutVersion(); int lv2 = FSImageTestUtil.GetFSImage(nn2).GetLayoutVersion(); int ns1 = FSImageTestUtil.GetFSImage(nn1).GetNamespaceID(); int ns2 = FSImageTestUtil.GetFSImage(nn2).GetNamespaceID(); NUnit.Framework.Assert.AreNotSame("namespace ids should be different", ns1, ns2); Log.Info("nn1: lv=" + lv1 + ";cid=" + cid1 + ";bpid=" + bpid1 + ";uri=" + nn1.GetNameNodeAddress ()); Log.Info("nn2: lv=" + lv2 + ";cid=" + cid2 + ";bpid=" + bpid2 + ";uri=" + nn2.GetNameNodeAddress ()); // check number of volumes in fsdataset DataNode dn = cluster.GetDataNodes()[0]; IDictionary <string, object> volInfos = dn.data.GetVolumeInfoMap(); NUnit.Framework.Assert.IsTrue("No volumes in the fsdataset", volInfos.Count > 0); int i = 0; foreach (KeyValuePair <string, object> e in volInfos) { Log.Info("vol " + i++ + ") " + e.Key + ": " + e.Value); } // number of volumes should be 2 - [data1, data2] NUnit.Framework.Assert.AreEqual("number of volumes is wrong", 2, volInfos.Count); foreach (BPOfferService bpos in dn.GetAllBpOs()) { Log.Info("BP: " + bpos); } BPOfferService bpos1 = dn.GetAllBpOs()[0]; BPOfferService bpos2 = dn.GetAllBpOs()[1]; // The order of bpos is not guaranteed, so fix the order if (GetNNSocketAddress(bpos1).Equals(nn2.GetNameNodeAddress())) { BPOfferService tmp = bpos1; bpos1 = bpos2; bpos2 = tmp; } NUnit.Framework.Assert.AreEqual("wrong nn address", GetNNSocketAddress(bpos1), nn1 .GetNameNodeAddress()); NUnit.Framework.Assert.AreEqual("wrong nn address", GetNNSocketAddress(bpos2), nn2 .GetNameNodeAddress()); NUnit.Framework.Assert.AreEqual("wrong bpid", bpos1.GetBlockPoolId(), bpid1); NUnit.Framework.Assert.AreEqual("wrong bpid", bpos2.GetBlockPoolId(), bpid2); NUnit.Framework.Assert.AreEqual("wrong cid", dn.GetClusterId(), cid1); NUnit.Framework.Assert.AreEqual("cid should be same", cid2, cid1); NUnit.Framework.Assert.AreEqual("namespace should be same", bpos1.bpNSInfo.namespaceID , ns1); NUnit.Framework.Assert.AreEqual("namespace should be same", bpos2.bpNSInfo.namespaceID , ns2); } finally { cluster.Shutdown(); } }
/// <exception cref="System.IO.IOException"/> private void DoRefreshNamenodes(IDictionary <string, IDictionary <string, IPEndPoint > > addrMap) { System.Diagnostics.Debug.Assert(Sharpen.Thread.HoldsLock(refreshNamenodesLock)); ICollection <string> toRefresh = Sets.NewLinkedHashSet(); ICollection <string> toAdd = Sets.NewLinkedHashSet(); ICollection <string> toRemove; lock (this) { // Step 1. For each of the new nameservices, figure out whether // it's an update of the set of NNs for an existing NS, // or an entirely new nameservice. foreach (string nameserviceId in addrMap.Keys) { if (bpByNameserviceId.Contains(nameserviceId)) { toRefresh.AddItem(nameserviceId); } else { toAdd.AddItem(nameserviceId); } } // Step 2. Any nameservices we currently have but are no longer present // need to be removed. toRemove = Sets.NewHashSet(Sets.Difference(bpByNameserviceId.Keys, addrMap.Keys)); System.Diagnostics.Debug.Assert(toRefresh.Count + toAdd.Count == addrMap.Count, "toAdd: " + Joiner.On(",").UseForNull("<default>").Join(toAdd) + " toRemove: " + Joiner. On(",").UseForNull("<default>").Join(toRemove) + " toRefresh: " + Joiner.On("," ).UseForNull("<default>").Join(toRefresh)); // Step 3. Start new nameservices if (!toAdd.IsEmpty()) { Log.Info("Starting BPOfferServices for nameservices: " + Joiner.On(",").UseForNull ("<default>").Join(toAdd)); foreach (string nsToAdd in toAdd) { AList <IPEndPoint> addrs = Lists.NewArrayList(addrMap[nsToAdd].Values); BPOfferService bpos = CreateBPOS(addrs); bpByNameserviceId[nsToAdd] = bpos; offerServices.AddItem(bpos); } } StartAll(); } // Step 4. Shut down old nameservices. This happens outside // of the synchronized(this) lock since they need to call // back to .remove() from another thread if (!toRemove.IsEmpty()) { Log.Info("Stopping BPOfferServices for nameservices: " + Joiner.On(",").UseForNull ("<default>").Join(toRemove)); foreach (string nsToRemove in toRemove) { BPOfferService bpos = bpByNameserviceId[nsToRemove]; bpos.Stop(); bpos.Join(); } } // they will call remove on their own // Step 5. Update nameservices whose NN list has changed if (!toRefresh.IsEmpty()) { Log.Info("Refreshing list of NNs for nameservices: " + Joiner.On(",").UseForNull( "<default>").Join(toRefresh)); foreach (string nsToRefresh in toRefresh) { BPOfferService bpos = bpByNameserviceId[nsToRefresh]; AList <IPEndPoint> addrs = Lists.NewArrayList(addrMap[nsToRefresh].Values); bpos.RefreshNNList(addrs); } } }
public _Answer_75(_BlockPoolManager_51 _enclosing, int idx, BPOfferService bpos) { this._enclosing = _enclosing; this.idx = idx; this.bpos = bpos; }
public _Supplier_397(BPOfferService bpos) { this.bpos = bpos; }
/// <exception cref="System.Exception"/> private void WaitForInitialization(BPOfferService bpos) { GenericTestUtils.WaitFor(new _Supplier_397(bpos), 100, 10000); }
/// <exception cref="System.Exception"/> private void WaitForOneToFail(BPOfferService bpos) { GenericTestUtils.WaitFor(new _Supplier_355(bpos), 100, 10000); }