LayoutVersion { public static int getMinimumCompatibleLayoutVersion( LayoutFeature[] features) { return getLastNonReservedFeature(features).getInfo() .getMinimumCompatibleLayoutVersion(); }  static void updateMap(Map<Integer, SortedSet<LayoutFeature>> map,
      LayoutFeature[] features); String getString(Map<Integer, SortedSet<LayoutFeature>> map,
      LayoutFeature[] values); static boolean supports(Map<Integer, SortedSet<LayoutFeature>> map,
      final LayoutFeature f, final int lv); static int getCurrentLayoutVersion(LayoutFeature[] features); static int getMinimumCompatibleLayoutVersion(
      LayoutFeature[] features); static final int BUGFIX_HDFS_2991_VERSION; }
@Test public void testNameNodeFeatureMinimumCompatibleLayoutVersions() { int baseLV = NameNodeLayoutVersion.Feature.TRUNCATE.getInfo() .getLayoutVersion(); EnumSet<NameNodeLayoutVersion.Feature> compatibleFeatures = EnumSet.of( NameNodeLayoutVersion.Feature.TRUNCATE, NameNodeLayoutVersion.Feature.APPEND_NEW_BLOCK, NameNodeLayoutVersion.Feature.QUOTA_BY_STORAGE_TYPE, NameNodeLayoutVersion.Feature.ERASURE_CODING, NameNodeLayoutVersion.Feature.EXPANDED_STRING_TABLE); for (LayoutFeature f : compatibleFeatures) { assertEquals(String.format("Expected minimum compatible layout version " + "%d for feature %s.", baseLV, f), baseLV, f.getInfo().getMinimumCompatibleLayoutVersion()); } List<LayoutFeature> features = new ArrayList<>(); features.addAll(EnumSet.allOf(LayoutVersion.Feature.class)); features.addAll(EnumSet.allOf(NameNodeLayoutVersion.Feature.class)); for (LayoutFeature f : features) { if (!compatibleFeatures.contains(f)) { assertEquals(String.format("Expected feature %s to have minimum " + "compatible layout version set to itself.", f), f.getInfo().getLayoutVersion(), f.getInfo().getMinimumCompatibleLayoutVersion()); } } }
@Test public void testNameNodeFeatureMinimumCompatibleLayoutVersionAscending() { LayoutFeature prevF = null; for (LayoutFeature f : EnumSet.allOf(NameNodeLayoutVersion.Feature.class)) { if (prevF != null) { assertTrue(String.format("Features %s and %s not listed in order of " + "minimum compatible layout version.", prevF, f), f.getInfo().getMinimumCompatibleLayoutVersion() <= prevF.getInfo().getMinimumCompatibleLayoutVersion()); } else { prevF = f; } } }
@Test public void testCurrentMinimumCompatibleLayoutVersion() { int expectedMinCompatLV = NameNodeLayoutVersion.Feature.TRUNCATE.getInfo() .getLayoutVersion(); int actualMinCompatLV = LayoutVersion.getMinimumCompatibleLayoutVersion( NameNodeLayoutVersion.Feature.values()); assertEquals("The minimum compatible layout version has changed. " + "Downgrade to prior versions is no longer possible. Please either " + "restore compatibility, or if the incompatibility is intentional, " + "then update this assertion.", expectedMinCompatLV, actualMinCompatLV); }