@Test public void shouldHandleLatest() throws IOException, ClassNotFoundException { IndexAnalysisSettings3 obj = new IndexAnalysisSettings3(); obj.setAnalyzerGuruVersion(ANALYZER_GURU_VERSION); Map<String, Long> actAnalyzersVersionNos = AnalyzerGuru.getAnalyzersVersionNos(); obj.setAnalyzersVersions(actAnalyzersVersionNos); obj.setProjectName(PROJECT_NAME); obj.setTabSize(TABSIZE); obj.setIndexedSymlinks(TEST_MAPPED_SYMLINKS); byte[] bin = obj.serialize(); IndexAnalysisSettingsUpgrader upgrader = new IndexAnalysisSettingsUpgrader(); IndexAnalysisSettings3 vLatest = upgrader.upgrade(bin, 3); assertNotNull("should get non-null from upgrader", vLatest); assertEquals("should have same projectName", PROJECT_NAME, vLatest.getProjectName()); assertEquals("should have same tabSize", TABSIZE, (int)vLatest.getTabSize()); assertEquals("should have same analyzerGuruVersion", ANALYZER_GURU_VERSION, (long)vLatest.getAnalyzerGuruVersion()); assertEquals("should have expected analyzer versions", vLatest.getAnalyzersVersions().size(), actAnalyzersVersionNos.size()); Object[] expectedVersionKeys = actAnalyzersVersionNos.keySet().stream().sorted().toArray(); assertArrayEquals("analyzer versions keysets should be equal", expectedVersionKeys, vLatest.getAnalyzersVersions().keySet().stream().sorted().toArray()); assertArrayEquals("analyzer versions values should be equal", getMapValues(actAnalyzersVersionNos, expectedVersionKeys), getMapValues(vLatest.getAnalyzersVersions(), expectedVersionKeys)); Object[] expectedSymlinkKeys = TEST_MAPPED_SYMLINKS.keySet().stream().sorted().toArray(); assertArrayEquals("index symlinks keysets should be equal", expectedSymlinkKeys, vLatest.getIndexedSymlinks().keySet().stream().sorted().toArray()); assertArrayEquals("index symlinks values should be equal", getMapValues(TEST_MAPPED_SYMLINKS, expectedSymlinkKeys), getMapValues(vLatest.getIndexedSymlinks(), expectedSymlinkKeys)); }
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);  }