@Before public void setUp() throws Exception { when(request.getRemoteAddr()).thenReturn("127.0.0.1"); when(messageHandler.handle(any(UpdateRequest.class), any(UpdateContext.class))) .thenReturn(new UpdateResponse(UpdateStatus.SUCCESS, "OK")); when(sourceContext.getCurrentSource()).thenReturn(Source.master("TEST")); }
@Override public void load(final List<Identifiable> proxy, final List<RpslObject> result) { final Map<Integer, RpslObject> loadedObjects = Maps.newHashMapWithExpectedSize(proxy.size()); Set<Integer> differences = loadObjects(proxy, loadedObjects); if (!differences.isEmpty()) { final Source originalSource = sourceContext.getCurrentSource(); LOGGER.info("Objects in source {} not found for ids: {}", originalSource, differences); if (originalSource.getType().equals(Source.Type.SLAVE)) { final Source masterSource = Source.master(originalSource.getName()); try { sourceContext.setCurrent(masterSource); differences = loadObjects(proxy, loadedObjects); if (!differences.isEmpty()) { LOGGER.info("Objects in source {} not found for ids: {}", masterSource, differences); } } catch (IllegalSourceException e) { LOGGER.debug("Source not configured: {}", masterSource, e); } finally { sourceContext.setCurrent(originalSource); } } } final List<RpslObject> rpslObjects = Lists.newArrayList(loadedObjects.values()); Collections.sort( rpslObjects, new Comparator<RpslObject>() { final List<Integer> requestedIds = Lists.newArrayList( Iterables.transform( proxy, new Function<Identifiable, Integer>() { @Override public Integer apply(final Identifiable input) { return input.getObjectId(); } })); @Override public int compare(final RpslObject o1, final RpslObject o2) { return requestedIds.indexOf(o1.getObjectId()) - requestedIds.indexOf(o2.getObjectId()); } }); // TODO [AK] Return result rather than adding all to the collection result.addAll(rpslObjects); }
private boolean sourceMatchesContext(final String source) { return (source != null) && sourceContext.getCurrentSource().getName().equals(CIString.ciString(source)); }