FileSetViewManager { public Pair<FileSetInfo, ViewInfo> getFileSetViewInfo(String fileSet) throws TerrapinGetException { FileSetInfo fileSetInfo = zkBackedFileSetInfoMap.get(fileSet); if (fileSetInfo == null) { throw new TerrapinGetException("File set " + fileSet + " not found.", TerrapinGetErrorCode.FILE_SET_NOT_FOUND); } if (!fileSetInfo.valid) { throw new TerrapinGetException("Invalid info for fileset " + fileSet, TerrapinGetErrorCode.FILE_SET_NOT_FOUND); } ViewInfo viewInfo = zkBackedViewInfoMap.get(fileSetInfo.servingInfo.helixResource); if (viewInfo == null) { LOG.warn("View not found for " + fileSet + ", trying backup resource"); fileSetInfo = fileSetInfoBackupMap.get(fileSet); if (fileSetInfo == null) { throw new TerrapinGetException("View for file set " + fileSet + " not found.", TerrapinGetErrorCode.INVALID_FILE_SET_VIEW); } viewInfo = zkBackedViewInfoMap.get(fileSetInfo.servingInfo.helixResource); if (viewInfo == null) { throw new TerrapinGetException("View not file set " + fileSet + " not found.", TerrapinGetErrorCode.INVALID_FILE_SET_VIEW); } } return new ImmutablePair(fileSetInfo, viewInfo); } FileSetViewManager(ZooKeeperClient zkClient,
                            String clusterName);   FileSetViewManager(String clusterName); Pair<FileSetInfo, ViewInfo> getFileSetViewInfo(String fileSet);  }
@Test public void testWithBackup() throws Exception { boolean exception = false; try { manager.getFileSetViewInfo(FILE_SET); } catch (TerrapinGetException e) { assertEquals(TerrapinGetErrorCode.FILE_SET_NOT_FOUND, e.getErrorCode()); exception = true; } assertTrue(exception); FileSetInfo fsInfo1 = new FileSetInfo( "file_set", "/terrapin/data/file_set/1", 1, (List)Lists.newArrayList(), new Options()); triggerFileSetInfoWatch(FILE_SET, fsInfo1); exception = false; try { manager.getFileSetViewInfo(FILE_SET); } catch (TerrapinGetException e) { assertEquals(TerrapinGetErrorCode.INVALID_FILE_SET_VIEW, e.getErrorCode()); exception = true; } assertTrue(exception); ExternalView externalView1 = new ExternalView("$terrapin$data$file_set$1"); externalView1.setStateMap("0", ImmutableMap.of("host1", "ONLINE")); ViewInfo viewInfo1 = new ViewInfo(externalView1); triggerViewInfoWatch(viewInfo1); Pair<FileSetInfo, ViewInfo> pair = manager.getFileSetViewInfo(FILE_SET); assertEquals(fsInfo1, pair.getLeft()); assertEquals(viewInfo1, pair.getRight()); FileSetInfo fsInfo2 = new FileSetInfo( FILE_SET, "/terrapin/data/file_set/2", 1, (List)Lists.newArrayList(), new Options()); triggerFileSetInfoWatch(FILE_SET, fsInfo2); pair = manager.getFileSetViewInfo(FILE_SET); assertEquals(fsInfo1, pair.getLeft()); assertEquals(viewInfo1, pair.getRight()); ExternalView externalView2 = new ExternalView("$terrapin$data$file_set$2"); externalView2.setStateMap("0", ImmutableMap.of("host2", "ONLINE")); ViewInfo viewInfo2 = new ViewInfo(externalView2); triggerViewInfoWatch(viewInfo2); pair = manager.getFileSetViewInfo(FILE_SET); assertEquals(fsInfo2, pair.getLeft()); assertEquals(viewInfo2, pair.getRight()); ExternalView externalView3 = new ExternalView("$terrapin$data$file_set$3"); externalView3.setStateMap("0", ImmutableMap.of("host3", "ONLINE")); ViewInfo viewInfo3 = new ViewInfo(externalView3); triggerViewInfoWatch(viewInfo3); pair = manager.getFileSetViewInfo(FILE_SET); assertEquals(fsInfo2, pair.getLeft()); assertEquals(viewInfo2, pair.getRight()); FileSetInfo fsInfo3 = new FileSetInfo( FILE_SET, "/terrapin/data/file_set/3", 1, (List)Lists.newArrayList(), new Options()); triggerFileSetInfoWatch(FILE_SET, fsInfo3); pair = manager.getFileSetViewInfo(FILE_SET); assertEquals(fsInfo3, pair.getLeft()); assertEquals(viewInfo3, pair.getRight()); }