PBHelper { public static NamenodeRole convert(NamenodeRoleProto role) { switch (role) { case NAMENODE: return NamenodeRole.NAMENODE; case BACKUP: return NamenodeRole.BACKUP; case CHECKPOINT: return NamenodeRole.CHECKPOINT; } return null; } private  PBHelper(); static ByteString getByteString(byte[] bytes); static NamenodeRole convert(NamenodeRoleProto role); static NamenodeRoleProto convert(NamenodeRole role); static BlockStoragePolicy[] convertStoragePolicies(
      List<BlockStoragePolicyProto> policyProtos); static BlockStoragePolicy convert(BlockStoragePolicyProto proto); static BlockStoragePolicyProto convert(BlockStoragePolicy policy); static StorageTypesProto convert(StorageType[] types); static StorageInfoProto convert(StorageInfo info); static StorageInfo convert(StorageInfoProto info, NodeType type); static NamenodeRegistrationProto convert(NamenodeRegistration reg); static NamenodeRegistration convert(NamenodeRegistrationProto reg); static DatanodeID convert(DatanodeIDProto dn); static DatanodeIDProto convert(DatanodeID dn); static DatanodeIDProto[] convert(DatanodeID[] did); static DatanodeID[] convert(DatanodeIDProto[] did); static BlockProto convert(Block b); static Block convert(BlockProto b); static BlockWithLocationsProto convert(BlockWithLocations blk); static BlockWithLocations convert(BlockWithLocationsProto b); static BlocksWithLocationsProto convert(BlocksWithLocations blks); static BlocksWithLocations convert(BlocksWithLocationsProto blocks); static BlockKeyProto convert(BlockKey key); static BlockKey convert(BlockKeyProto k); static ExportedBlockKeysProto convert(ExportedBlockKeys keys); static ExportedBlockKeys convert(ExportedBlockKeysProto keys); static CheckpointSignatureProto convert(CheckpointSignature s); static CheckpointSignature convert(CheckpointSignatureProto s); static RemoteEditLogProto convert(RemoteEditLog log); static RemoteEditLog convert(RemoteEditLogProto l); static RemoteEditLogManifestProto convert(
      RemoteEditLogManifest manifest); static RemoteEditLogManifest convert(
      RemoteEditLogManifestProto manifest); static CheckpointCommandProto convert(CheckpointCommand cmd); static NamenodeCommandProto convert(NamenodeCommand cmd); static BlockKey[] convertBlockKeys(List<BlockKeyProto> list); static NamespaceInfo convert(NamespaceInfoProto info); static NamenodeCommand convert(NamenodeCommandProto cmd); static ExtendedBlock convert(ExtendedBlockProto eb); static ExtendedBlockProto convert(final ExtendedBlock b); static RecoveringBlockProto convert(RecoveringBlock b); static RecoveringBlock convert(RecoveringBlockProto b); static DatanodeInfoProto.AdminState convert(
      final DatanodeInfo.AdminStates inAs); static DatanodeInfo convert(DatanodeInfoProto di); static DatanodeInfoProto convertDatanodeInfo(DatanodeInfo di); static DatanodeInfo[] convert(DatanodeInfoProto di[]); static List<? extends HdfsProtos.DatanodeInfoProto> convert(
      DatanodeInfo[] dnInfos); static List<? extends HdfsProtos.DatanodeInfoProto> convert(
      DatanodeInfo[] dnInfos, int startIdx); static DatanodeInfo[] convert(List<DatanodeInfoProto> list); static DatanodeInfoProto convert(DatanodeInfo info); static DatanodeStorageReportProto convertDatanodeStorageReport(
      DatanodeStorageReport report); static List<DatanodeStorageReportProto> convertDatanodeStorageReports(
      DatanodeStorageReport[] reports); static DatanodeStorageReport convertDatanodeStorageReport(
      DatanodeStorageReportProto proto); static DatanodeStorageReport[] convertDatanodeStorageReports(
      List<DatanodeStorageReportProto> protos); static AdminStates convert(AdminState adminState); static LocatedBlockProto convert(LocatedBlock b); static LocatedBlock convert(LocatedBlockProto proto); static TokenProto convert(Token<?> tok); static Token<BlockTokenIdentifier> convert(
      TokenProto blockToken); static Token<DelegationTokenIdentifier> convertDelegationToken(
      TokenProto blockToken); static ReplicaState convert(ReplicaStateProto state); static ReplicaStateProto convert(ReplicaState state); static DatanodeRegistrationProto convert(
      DatanodeRegistration registration); static DatanodeRegistration convert(DatanodeRegistrationProto proto); static DatanodeCommand convert(DatanodeCommandProto proto); static BalancerBandwidthCommandProto convert(
      BalancerBandwidthCommand bbCmd); static KeyUpdateCommandProto convert(KeyUpdateCommand cmd); static BlockRecoveryCommandProto convert(BlockRecoveryCommand cmd); static FinalizeCommandProto convert(FinalizeCommand cmd); static BlockCommandProto convert(BlockCommand cmd); static BlockIdCommandProto convert(BlockIdCommand cmd); static DatanodeCommandProto convert(DatanodeCommand datanodeCommand); static KeyUpdateCommand convert(KeyUpdateCommandProto keyUpdateCmd); static FinalizeCommand convert(FinalizeCommandProto finalizeCmd); static BlockRecoveryCommand convert(
      BlockRecoveryCommandProto recoveryCmd); static BlockCommand convert(BlockCommandProto blkCmd); static BlockIdCommand convert(BlockIdCommandProto blkIdCmd); static DatanodeInfo[] convert(DatanodeInfosProto datanodeInfosProto); static BalancerBandwidthCommand convert(
      BalancerBandwidthCommandProto balancerCmd); static ReceivedDeletedBlockInfoProto convert(
      ReceivedDeletedBlockInfo receivedDeletedBlockInfo); static ReceivedDeletedBlockInfo convert(
      ReceivedDeletedBlockInfoProto proto); static NamespaceInfoProto convert(NamespaceInfo info); static LocatedBlockProto[] convertLocatedBlock(LocatedBlock[] lb); static LocatedBlock[] convertLocatedBlock(LocatedBlockProto[] lb); static List<LocatedBlock> convertLocatedBlock(
      List<LocatedBlockProto> lb); static List<LocatedBlockProto> convertLocatedBlock2(List<LocatedBlock> lb); static LocatedBlocks convert(LocatedBlocksProto lb); static LocatedBlocksProto convert(LocatedBlocks lb); static DataEncryptionKey convert(DataEncryptionKeyProto bet); static DataEncryptionKeyProto convert(DataEncryptionKey bet); static FsServerDefaults convert(FsServerDefaultsProto fs); static FsServerDefaultsProto convert(FsServerDefaults fs); static FsPermissionProto convert(FsPermission p); static FsPermission convert(FsPermissionProto p); static int convertCreateFlag(EnumSetWritable<CreateFlag> flag); static EnumSetWritable<CreateFlag> convertCreateFlag(int flag); static int convertCacheFlags(EnumSet<CacheFlag> flags); static EnumSet<CacheFlag> convertCacheFlags(int flags); static HdfsFileStatus convert(HdfsFileStatusProto fs); static SnapshottableDirectoryStatus convert(
      SnapshottableDirectoryStatusProto sdirStatusProto); static HdfsFileStatusProto convert(HdfsFileStatus fs); static SnapshottableDirectoryStatusProto convert(
      SnapshottableDirectoryStatus status); static HdfsFileStatusProto[] convert(HdfsFileStatus[] fs); static HdfsFileStatus[] convert(HdfsFileStatusProto[] fs); static DirectoryListing convert(DirectoryListingProto dl); static DirectoryListingProto convert(DirectoryListing d); static long[] convert(GetFsStatsResponseProto res); static GetFsStatsResponseProto convert(long[] fsStats); static DatanodeReportTypeProto convert(DatanodeReportType t); static DatanodeReportType convert(DatanodeReportTypeProto t); static SafeModeActionProto convert(
      SafeModeAction a); static SafeModeAction convert(
      ClientNamenodeProtocolProtos.SafeModeActionProto a); static RollingUpgradeActionProto convert(RollingUpgradeAction a); static RollingUpgradeAction convert(RollingUpgradeActionProto a); static RollingUpgradeStatusProto convertRollingUpgradeStatus(
      RollingUpgradeStatus status); static RollingUpgradeStatus convert(RollingUpgradeStatusProto proto); static RollingUpgradeInfoProto convert(RollingUpgradeInfo info); static RollingUpgradeInfo convert(RollingUpgradeInfoProto proto); static CorruptFileBlocks convert(CorruptFileBlocksProto c); static CorruptFileBlocksProto convert(CorruptFileBlocks c); static ContentSummary convert(ContentSummaryProto cs); static ContentSummaryProto convert(ContentSummary cs); static NNHAStatusHeartbeat convert(NNHAStatusHeartbeatProto s); static NNHAStatusHeartbeatProto convert(NNHAStatusHeartbeat hb); static DatanodeStorageProto convert(DatanodeStorage s); static List<StorageTypeProto> convertStorageTypes(
      StorageType[] types); static List<StorageTypeProto> convertStorageTypes(
      StorageType[] types, int startIdx); static StorageTypeProto convertStorageType(StorageType type); static DatanodeStorage convert(DatanodeStorageProto s); static StorageType convertStorageType(StorageTypeProto type); static StorageType[] convertStorageTypes(
      List<StorageTypeProto> storageTypesList, int expectedSize); static StorageReportProto convert(StorageReport r); static StorageReport convert(StorageReportProto p); static StorageReport[] convertStorageReports(
      List<StorageReportProto> list); static List<StorageReportProto> convertStorageReports(StorageReport[] storages); static JournalInfo convert(JournalInfoProto info); static JournalInfoProto convert(JournalInfo j); static SnapshottableDirectoryStatus[] convert(
      SnapshottableDirectoryListingProto sdlp); static SnapshottableDirectoryListingProto convert(
      SnapshottableDirectoryStatus[] status); static DiffReportEntry convert(SnapshotDiffReportEntryProto entry); static SnapshotDiffReportEntryProto convert(DiffReportEntry entry); static SnapshotDiffReport convert(SnapshotDiffReportProto reportProto); static SnapshotDiffReportProto convert(SnapshotDiffReport report); static DataChecksum.Type convert(HdfsProtos.ChecksumTypeProto type); static CacheDirectiveInfoProto convert(CacheDirectiveInfo info); static CacheDirectiveInfo convert(CacheDirectiveInfoProto proto); static CacheDirectiveInfoExpirationProto convert(
      CacheDirectiveInfo.Expiration expiration); static CacheDirectiveInfo.Expiration convert(
      CacheDirectiveInfoExpirationProto proto); static CacheDirectiveStatsProto convert(CacheDirectiveStats stats); static CacheDirectiveStats convert(CacheDirectiveStatsProto proto); static CacheDirectiveEntryProto convert(CacheDirectiveEntry entry); static CacheDirectiveEntry convert(CacheDirectiveEntryProto proto); static CachePoolInfoProto convert(CachePoolInfo info); static CachePoolInfo convert(CachePoolInfoProto proto); static CachePoolStatsProto convert(CachePoolStats stats); static CachePoolStats convert(CachePoolStatsProto proto); static CachePoolEntryProto convert(CachePoolEntry entry); static CachePoolEntry convert(CachePoolEntryProto proto); static HdfsProtos.ChecksumTypeProto convert(DataChecksum.Type type); static DatanodeLocalInfoProto convert(DatanodeLocalInfo info); static DatanodeLocalInfo convert(DatanodeLocalInfoProto proto); static InputStream vintPrefixed(final InputStream input); static FsActionProto convert(FsAction v); static FsAction convert(FsActionProto v); static List<AclEntryProto> convertAclEntryProto(
      List<AclEntry> aclSpec); static List<AclEntry> convertAclEntry(List<AclEntryProto> aclSpec); static AclStatus convert(GetAclStatusResponseProto e); static GetAclStatusResponseProto convert(AclStatus e); static XAttrProto convertXAttrProto(XAttr a); static List<XAttrProto> convertXAttrProto(
      List<XAttr> xAttrSpec); static int convert(EnumSet<XAttrSetFlag> flag); static EnumSet<XAttrSetFlag> convert(int flag); static XAttr convertXAttr(XAttrProto a); static List<XAttr> convertXAttrs(List<XAttrProto> xAttrSpec); static List<XAttr> convert(GetXAttrsResponseProto a); static GetXAttrsResponseProto convertXAttrsResponse(
      List<XAttr> xAttrs); static List<XAttr> convert(ListXAttrsResponseProto a); static ListXAttrsResponseProto convertListXAttrsResponse(
    List<XAttr> names); static EncryptionZoneProto convert(EncryptionZone zone); static EncryptionZone convert(EncryptionZoneProto proto); static ShortCircuitShmSlotProto convert(SlotId slotId); static ShortCircuitShmIdProto convert(ShmId shmId); static SlotId convert(ShortCircuitShmSlotProto slotId); static ShmId convert(ShortCircuitShmIdProto shmId); static EventBatchList convert(GetEditsFromTxidResponseProto resp); static GetEditsFromTxidResponseProto convertEditsResponse(EventBatchList el); static CipherOptionProto convert(CipherOption option); static CipherOption convert(CipherOptionProto proto); static List<CipherOptionProto> convertCipherOptions(
      List<CipherOption> options); static List<CipherOption> convertCipherOptionProtos(
      List<CipherOptionProto> protos); static CipherSuiteProto convert(CipherSuite suite); static CipherSuite convert(CipherSuiteProto proto); static List<CryptoProtocolVersionProto> convert(
      CryptoProtocolVersion[] versions); static CryptoProtocolVersion[] convertCryptoProtocolVersions(
      List<CryptoProtocolVersionProto> protos); static CryptoProtocolVersion convert(CryptoProtocolVersionProto
      proto); static CryptoProtocolVersionProto convert(CryptoProtocolVersion
      version); static HdfsProtos.FileEncryptionInfoProto convert(
      FileEncryptionInfo info); static HdfsProtos.PerFileEncryptionInfoProto convertPerFileEncInfo(
      FileEncryptionInfo info); static HdfsProtos.ZoneEncryptionInfoProto convert(
      CipherSuite suite, CryptoProtocolVersion version, String keyName); static FileEncryptionInfo convert(
      HdfsProtos.FileEncryptionInfoProto proto); static FileEncryptionInfo convert(
      HdfsProtos.PerFileEncryptionInfoProto fileProto,
      CipherSuite suite, CryptoProtocolVersion version, String keyName); static BlockReportContext convert(BlockReportContextProto proto); static BlockReportContextProto convert(BlockReportContext context);  }
@Test public void testConvertNamenodeRole() { assertEquals(NamenodeRoleProto.BACKUP, PBHelper.convert(NamenodeRole.BACKUP)); assertEquals(NamenodeRoleProto.CHECKPOINT, PBHelper.convert(NamenodeRole.CHECKPOINT)); assertEquals(NamenodeRoleProto.NAMENODE, PBHelper.convert(NamenodeRole.NAMENODE)); assertEquals(NamenodeRole.BACKUP, PBHelper.convert(NamenodeRoleProto.BACKUP)); assertEquals(NamenodeRole.CHECKPOINT, PBHelper.convert(NamenodeRoleProto.CHECKPOINT)); assertEquals(NamenodeRole.NAMENODE, PBHelper.convert(NamenodeRoleProto.NAMENODE)); }
@Test public void testConvertStoragInfo() { StorageInfo info = getStorageInfo(NodeType.NAME_NODE); StorageInfoProto infoProto = PBHelper.convert(info); StorageInfo info2 = PBHelper.convert(infoProto, NodeType.NAME_NODE); assertEquals(info.getClusterID(), info2.getClusterID()); assertEquals(info.getCTime(), info2.getCTime()); assertEquals(info.getLayoutVersion(), info2.getLayoutVersion()); assertEquals(info.getNamespaceID(), info2.getNamespaceID()); }
@Test public void testConvertNamenodeRegistration() { StorageInfo info = getStorageInfo(NodeType.NAME_NODE); NamenodeRegistration reg = new NamenodeRegistration("address:999", "http:1000", info, NamenodeRole.NAMENODE); NamenodeRegistrationProto regProto = PBHelper.convert(reg); NamenodeRegistration reg2 = PBHelper.convert(regProto); assertEquals(reg.getAddress(), reg2.getAddress()); assertEquals(reg.getClusterID(), reg2.getClusterID()); assertEquals(reg.getCTime(), reg2.getCTime()); assertEquals(reg.getHttpAddress(), reg2.getHttpAddress()); assertEquals(reg.getLayoutVersion(), reg2.getLayoutVersion()); assertEquals(reg.getNamespaceID(), reg2.getNamespaceID()); assertEquals(reg.getRegistrationID(), reg2.getRegistrationID()); assertEquals(reg.getRole(), reg2.getRole()); assertEquals(reg.getVersion(), reg2.getVersion()); }
@Test public void testConvertDatanodeID() { DatanodeID dn = DFSTestUtil.getLocalDatanodeID(); DatanodeIDProto dnProto = PBHelper.convert(dn); DatanodeID dn2 = PBHelper.convert(dnProto); compare(dn, dn2); }
@Test public void testConvertBlock() { Block b = new Block(1, 100, 3); BlockProto bProto = PBHelper.convert(b); Block b2 = PBHelper.convert(bProto); assertEquals(b, b2); }
@Test public void testConvertBlockWithLocations() { BlockWithLocations locs = getBlockWithLocations(1); BlockWithLocationsProto locsProto = PBHelper.convert(locs); BlockWithLocations locs2 = PBHelper.convert(locsProto); compare(locs, locs2); }
@Test public void testConvertBlocksWithLocations() { BlockWithLocations[] list = new BlockWithLocations[] { getBlockWithLocations(1), getBlockWithLocations(2) }; BlocksWithLocations locs = new BlocksWithLocations(list); BlocksWithLocationsProto locsProto = PBHelper.convert(locs); BlocksWithLocations locs2 = PBHelper.convert(locsProto); BlockWithLocations[] blocks = locs.getBlocks(); BlockWithLocations[] blocks2 = locs2.getBlocks(); assertEquals(blocks.length, blocks2.length); for (int i = 0; i < blocks.length; i++) { compare(blocks[i], blocks2[i]); } }
@Test public void testConvertBlockKey() { BlockKey key = getBlockKey(1); BlockKeyProto keyProto = PBHelper.convert(key); BlockKey key1 = PBHelper.convert(keyProto); compare(key, key1); }
@Test public void testConvertExportedBlockKeys() { BlockKey[] keys = new BlockKey[] { getBlockKey(2), getBlockKey(3) }; ExportedBlockKeys expKeys = new ExportedBlockKeys(true, 9, 10, getBlockKey(1), keys); ExportedBlockKeysProto expKeysProto = PBHelper.convert(expKeys); ExportedBlockKeys expKeys1 = PBHelper.convert(expKeysProto); compare(expKeys, expKeys1); }
@Test public void testConvertCheckpointSignature() { CheckpointSignature s = new CheckpointSignature( getStorageInfo(NodeType.NAME_NODE), "bpid", 100, 1); CheckpointSignatureProto sProto = PBHelper.convert(s); CheckpointSignature s1 = PBHelper.convert(sProto); assertEquals(s.getBlockpoolID(), s1.getBlockpoolID()); assertEquals(s.getClusterID(), s1.getClusterID()); assertEquals(s.getCTime(), s1.getCTime()); assertEquals(s.getCurSegmentTxId(), s1.getCurSegmentTxId()); assertEquals(s.getLayoutVersion(), s1.getLayoutVersion()); assertEquals(s.getMostRecentCheckpointTxId(), s1.getMostRecentCheckpointTxId()); assertEquals(s.getNamespaceID(), s1.getNamespaceID()); }
@Test public void testConvertRemoteEditLog() { RemoteEditLog l = new RemoteEditLog(1, 100); RemoteEditLogProto lProto = PBHelper.convert(l); RemoteEditLog l1 = PBHelper.convert(lProto); compare(l, l1); }
@Test public void testConvertRemoteEditLogManifest() { List<RemoteEditLog> logs = new ArrayList<RemoteEditLog>(); logs.add(new RemoteEditLog(1, 10)); logs.add(new RemoteEditLog(11, 20)); RemoteEditLogManifest m = new RemoteEditLogManifest(logs); RemoteEditLogManifestProto mProto = PBHelper.convert(m); RemoteEditLogManifest m1 = PBHelper.convert(mProto); List<RemoteEditLog> logs1 = m1.getLogs(); assertEquals(logs.size(), logs1.size()); for (int i = 0; i < logs.size(); i++) { compare(logs.get(i), logs1.get(i)); } }
@Test public void testConvertExtendedBlock() { ExtendedBlock b = getExtendedBlock(); ExtendedBlockProto bProto = PBHelper.convert(b); ExtendedBlock b1 = PBHelper.convert(bProto); assertEquals(b, b1); b.setBlockId(-1); bProto = PBHelper.convert(b); b1 = PBHelper.convert(bProto); assertEquals(b, b1); }
@Test public void testConvertRecoveringBlock() { DatanodeInfo di1 = DFSTestUtil.getLocalDatanodeInfo(); DatanodeInfo di2 = DFSTestUtil.getLocalDatanodeInfo(); DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 }; RecoveringBlock b = new RecoveringBlock(getExtendedBlock(), dnInfo, 3); RecoveringBlockProto bProto = PBHelper.convert(b); RecoveringBlock b1 = PBHelper.convert(bProto); assertEquals(b.getBlock(), b1.getBlock()); DatanodeInfo[] dnInfo1 = b1.getLocations(); assertEquals(dnInfo.length, dnInfo1.length); for (int i=0; i < dnInfo.length; i++) { compare(dnInfo[0], dnInfo1[0]); } }
@Test public void testConvertBlockRecoveryCommand() { DatanodeInfo di1 = DFSTestUtil.getLocalDatanodeInfo(); DatanodeInfo di2 = DFSTestUtil.getLocalDatanodeInfo(); DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 }; List<RecoveringBlock> blks = ImmutableList.of( new RecoveringBlock(getExtendedBlock(1), dnInfo, 3), new RecoveringBlock(getExtendedBlock(2), dnInfo, 3) ); BlockRecoveryCommand cmd = new BlockRecoveryCommand(blks); BlockRecoveryCommandProto proto = PBHelper.convert(cmd); assertEquals(1, proto.getBlocks(0).getBlock().getB().getBlockId()); assertEquals(2, proto.getBlocks(1).getBlock().getB().getBlockId()); BlockRecoveryCommand cmd2 = PBHelper.convert(proto); List<RecoveringBlock> cmd2Blks = Lists.newArrayList( cmd2.getRecoveringBlocks()); assertEquals(blks.get(0).getBlock(), cmd2Blks.get(0).getBlock()); assertEquals(blks.get(1).getBlock(), cmd2Blks.get(1).getBlock()); assertEquals(Joiner.on(",").join(blks), Joiner.on(",").join(cmd2Blks)); assertEquals(cmd.toString(), cmd2.toString()); }
@Test public void testConvertBlockToken() { Token<BlockTokenIdentifier> token = new Token<BlockTokenIdentifier>( "identifier".getBytes(), "password".getBytes(), new Text("kind"), new Text("service")); TokenProto tokenProto = PBHelper.convert(token); Token<BlockTokenIdentifier> token2 = PBHelper.convert(tokenProto); compare(token, token2); }
@Test public void testConvertNamespaceInfo() { NamespaceInfo info = new NamespaceInfo(37, "clusterID", "bpID", 2300); NamespaceInfoProto proto = PBHelper.convert(info); NamespaceInfo info2 = PBHelper.convert(proto); compare(info, info2); assertEquals(info.getBlockPoolID(), info2.getBlockPoolID()); assertEquals(info.getBuildVersion(), info2.getBuildVersion()); }
@Test public void testConvertLocatedBlockNoStorageMedia() { LocatedBlock lb = createLocatedBlockNoStorageMedia(); LocatedBlockProto lbProto = PBHelper.convert(lb); LocatedBlock lb2 = PBHelper.convert(lbProto); compare(lb,lb2); }
@Test public void testConvertDatanodeRegistration() { DatanodeID dnId = DFSTestUtil.getLocalDatanodeID(); BlockKey[] keys = new BlockKey[] { getBlockKey(2), getBlockKey(3) }; ExportedBlockKeys expKeys = new ExportedBlockKeys(true, 9, 10, getBlockKey(1), keys); DatanodeRegistration reg = new DatanodeRegistration(dnId, new StorageInfo(NodeType.DATA_NODE), expKeys, "3.0.0"); DatanodeRegistrationProto proto = PBHelper.convert(reg); DatanodeRegistration reg2 = PBHelper.convert(proto); compare(reg.getStorageInfo(), reg2.getStorageInfo()); compare(reg.getExportedKeys(), reg2.getExportedKeys()); compare(reg, reg2); assertEquals(reg.getSoftwareVersion(), reg2.getSoftwareVersion()); }
@Test public void TestConvertDatanodeStorage() { DatanodeStorage dns1 = new DatanodeStorage( "id1", DatanodeStorage.State.NORMAL, StorageType.SSD); DatanodeStorageProto proto = PBHelper.convert(dns1); DatanodeStorage dns2 = PBHelper.convert(proto); compare(dns1, dns2); }
@Test public void testConvertBlockCommand() { Block[] blocks = new Block[] { new Block(21), new Block(22) }; DatanodeInfo[][] dnInfos = new DatanodeInfo[][] { new DatanodeInfo[1], new DatanodeInfo[2] }; dnInfos[0][0] = DFSTestUtil.getLocalDatanodeInfo(); dnInfos[1][0] = DFSTestUtil.getLocalDatanodeInfo(); dnInfos[1][1] = DFSTestUtil.getLocalDatanodeInfo(); String[][] storageIDs = {{"s00"}, {"s10", "s11"}}; StorageType[][] storageTypes = {{StorageType.DEFAULT}, {StorageType.DEFAULT, StorageType.DEFAULT}}; BlockCommand bc = new BlockCommand(DatanodeProtocol.DNA_TRANSFER, "bp1", blocks, dnInfos, storageTypes, storageIDs); BlockCommandProto bcProto = PBHelper.convert(bc); BlockCommand bc2 = PBHelper.convert(bcProto); assertEquals(bc.getAction(), bc2.getAction()); assertEquals(bc.getBlocks().length, bc2.getBlocks().length); Block[] blocks2 = bc2.getBlocks(); for (int i = 0; i < blocks.length; i++) { assertEquals(blocks[i], blocks2[i]); } DatanodeInfo[][] dnInfos2 = bc2.getTargets(); assertEquals(dnInfos.length, dnInfos2.length); for (int i = 0; i < dnInfos.length; i++) { DatanodeInfo[] d1 = dnInfos[i]; DatanodeInfo[] d2 = dnInfos2[i]; assertEquals(d1.length, d2.length); for (int j = 0; j < d1.length; j++) { compare(d1[j], d2[j]); } } }
@Test public void testChecksumTypeProto() { assertEquals(DataChecksum.Type.NULL, PBHelper.convert(HdfsProtos.ChecksumTypeProto.CHECKSUM_NULL)); assertEquals(DataChecksum.Type.CRC32, PBHelper.convert(HdfsProtos.ChecksumTypeProto.CHECKSUM_CRC32)); assertEquals(DataChecksum.Type.CRC32C, PBHelper.convert(HdfsProtos.ChecksumTypeProto.CHECKSUM_CRC32C)); assertEquals(PBHelper.convert(DataChecksum.Type.NULL), HdfsProtos.ChecksumTypeProto.CHECKSUM_NULL); assertEquals(PBHelper.convert(DataChecksum.Type.CRC32), HdfsProtos.ChecksumTypeProto.CHECKSUM_CRC32); assertEquals(PBHelper.convert(DataChecksum.Type.CRC32C), HdfsProtos.ChecksumTypeProto.CHECKSUM_CRC32C); }
@Test public void testAclStatusProto() { AclEntry e = new AclEntry.Builder().setName("test") .setPermission(FsAction.READ_EXECUTE).setScope(AclEntryScope.DEFAULT) .setType(AclEntryType.OTHER).build(); AclStatus s = new AclStatus.Builder().owner("foo").group("bar").addEntry(e) .build(); Assert.assertEquals(s, PBHelper.convert(PBHelper.convert(s))); }