LocalResolver extends RouterResolver<String, String> { public LocalResolver(final Configuration conf, final Router routerService) { super(conf, routerService); } LocalResolver(final Configuration conf, final Router routerService);   }
@Test @SuppressWarnings("unchecked") public void testLocalResolver() throws IOException { Configuration conf = new Configuration(); Router router = mock(Router.class); StateStoreService stateStore = mock(StateStoreService.class); MembershipStore membership = mock(MembershipStore.class); when(router.getStateStore()).thenReturn(stateStore); when(stateStore.getRegisteredRecordStore(any(Class.class))) .thenReturn(membership); GetNamenodeRegistrationsResponse response = GetNamenodeRegistrationsResponse.newInstance(); List<MembershipState> records = new LinkedList<>(); records.add(newMembershipState("client0", "subcluster0")); records.add(newMembershipState("client1", "subcluster1")); records.add(newMembershipState("client2", "subcluster2")); response.setNamenodeMemberships(records); when(membership.getNamenodeRegistrations( any(GetNamenodeRegistrationsRequest.class))).thenReturn(response); StringBuilder sb = new StringBuilder("clientX"); LocalResolver localResolver = new LocalResolver(conf, router); LocalResolver spyLocalResolver = spy(localResolver); doAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return sb.toString(); } }).when(spyLocalResolver).getClientAddr(); MultipleDestinationMountTableResolver resolver = new MultipleDestinationMountTableResolver(conf, router); resolver.addResolver(DestinationOrder.LOCAL, spyLocalResolver); Map<String, String> mapLocal = new HashMap<>(); mapLocal.put("subcluster0", "/local"); mapLocal.put("subcluster1", "/local"); mapLocal.put("subcluster2", "/local"); MountTable localEntry = MountTable.newInstance("/local", mapLocal); localEntry.setDestOrder(DestinationOrder.LOCAL); resolver.addEntry(localEntry); PathLocation dest = resolver.getDestinationForPath("/local/file0.txt"); assertDestination("subcluster0", dest); setClient(sb, "client2"); dest = resolver.getDestinationForPath("/local/file0.txt"); assertDestination("subcluster2", dest); setClient(sb, "client1"); dest = resolver.getDestinationForPath("/local/file0.txt"); assertDestination("subcluster1", dest); setClient(sb, "client0"); dest = resolver.getDestinationForPath("/local/file0.txt"); assertDestination("subcluster0", dest); }