@Override public IndexInfo getInfo(String indexPath) throws IOException { String type = getIndexType(indexPath); if (type == null) return null; IndexInfoProvider infoProvider = infoProviders.get(type); if (infoProvider == null) { return new SimpleIndexInfo(indexPath, type); } return infoProvider.getInfo(indexPath); }
@Override public IndexInfo getInfo(String indexPath) throws IOException { String type = getIndexType(indexPath); if (type == null) return null; IndexInfoProvider infoProvider = infoProviders.get(type); if (infoProvider == null) { return new SimpleIndexInfo(indexPath, type); } return infoProvider.getInfo(indexPath); }
@Override public IndexInfo getInfo(String indexPath) throws IOException { String type = getIndexType(indexPath); if (type == null) return null; IndexInfoProvider infoProvider = infoProviders.get(type); if (infoProvider == null) { return new SimpleIndexInfo(indexPath, type); } return infoProvider.getInfo(indexPath); }
@Test public void allIndexInfo() throws Exception{ pathService.paths = Lists.newArrayList("/oak:index/a", "/oak:index/b", "/oak:index/c", "/oak:index/d"); NodeBuilder builder = store.getRoot().builder(); builder.child("oak:index").child("a"); //Index with no type builder.child("oak:index").child("b").setProperty("type", "type-b"); //No backing info provider builder.child("oak:index").child("c").setProperty("type", "type-c"); //Info provider throws exception builder.child("oak:index").child("d").setProperty("type", "type-d"); //Info provider returns result store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); IndexInfoProvider type_c = mock(IndexInfoProvider.class); when(type_c.getInfo(anyString())).thenThrow(new RuntimeException()); when(type_c.getType()).thenReturn("type-c"); IndexInfo infod = mock(IndexInfo.class); when(infod.getType()).thenReturn("type-d"); when(infod.getAsyncLaneName()).thenReturn("async-d"); IndexInfoProvider type_d = mock(IndexInfoProvider.class); when(type_d.getInfo(anyString())).thenReturn(infod); when(type_d.getType()).thenReturn("type-d"); service.bindInfoProviders(type_c); service.bindInfoProviders(type_d); List<IndexInfo> infos = Lists.newArrayList(service.getAllIndexInfo()); //Result would only have 2 entries. One throwing exception would be ignored assertEquals(2, infos.size()); for (IndexInfo info : infos) { if (info.getType().equals("type-d")){ assertEquals("async-d", info.getAsyncLaneName()); } } }
@Test public void indexInfo() throws Exception{ //1. Test Empty assertNull(service.getInfo("/nonExistingPath")); //2. Test when no backing InfoProvider NodeBuilder builder = store.getRoot().builder(); builder.child("oak:index").child("fooIndex").setProperty("type", "foo"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); IndexInfo info = service.getInfo("/oak:index/fooIndex"); assertNotNull(info); assertEquals("/oak:index/fooIndex", info.getIndexPath()); assertEquals("foo", info.getType()); //3. Test when backing InfoProvider IndexInfo testInfo = mock(IndexInfo.class); when(testInfo.getIndexPath()).thenReturn("/some/other/path"); IndexInfoProvider infoProvider = mock(IndexInfoProvider.class); when(infoProvider.getType()).thenReturn("foo"); when(infoProvider.getInfo(anyString())).thenReturn(testInfo); service.bindInfoProviders(infoProvider); IndexInfo info2 = service.getInfo("/oak:index/fooIndex"); assertNotNull(info2); assertEquals("/some/other/path", info2.getIndexPath()); }