@Test public void shouldUpgradeV2() throws IOException, ClassNotFoundException { IndexAnalysisSettings obj = new IndexAnalysisSettings(); obj.setAnalyzerGuruVersion(ANALYZER_GURU_VERSION); Map<String, Long> actAnalyzersVersionNos = AnalyzerGuru.getAnalyzersVersionNos(); obj.setAnalyzersVersions(actAnalyzersVersionNos); obj.setProjectName(PROJECT_NAME); obj.setTabSize(TABSIZE); obj.setAnalyzersVersions(actAnalyzersVersionNos); byte[] bin = obj.serialize(); IndexAnalysisSettingsUpgrader upgrader = new IndexAnalysisSettingsUpgrader(); IndexAnalysisSettings3 v3 = upgrader.upgrade(bin, 2); assertNotNull("should get non-null from upgrader", v3); assertEquals("should have same projectName", PROJECT_NAME, v3.getProjectName()); assertEquals("should have same tabSize", TABSIZE, (int)v3.getTabSize()); assertEquals("should have same analyzerGuruVersion", ANALYZER_GURU_VERSION, (long)v3.getAnalyzerGuruVersion()); assertEquals("should have expected analyzer versions", v3.getAnalyzersVersions().size(), actAnalyzersVersionNos.size()); assertTrue("should have no indexedSymlinks", v3.getIndexedSymlinks().isEmpty()); }
public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } } }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }  }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }  IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion); }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }  IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion);  }