FetcherDefault extends AbstractExtensionPoint implements Fetcher, Function<Resource, FetchedData> { public String getUserAgent(){ if (userAgents == null || userAgents.isEmpty()){ return null; } String agent = userAgents.get(userAgentIndex); synchronized (this) { userAgentIndex = (userAgentIndex + 1) % userAgents.size(); } return agent; } FetcherDefault(); @Override void init(JobContext context, String pluginId); String getUserAgent(); @Override Iterator<FetchedData> fetch(Iterator<Resource> resources); FetchedData fetch(Resource resource); @Override FetchedData apply(Resource resource); static final Logger LOG; static final Integer CONNECT_TIMEOUT; static final Integer READ_TIMEOUT; static final Integer CONTENT_LIMIT; static final Integer DEFAULT_ERROR_CODE; static final String USER_AGENT; static final String TRUNCATED; }
@Test public void testUserAgentRotation(){ String ua1 = fetcher.getUserAgent(); String ua2 = fetcher.getUserAgent(); assertNotSame(ua1, ua2); }