Skip to content

Instantly share code, notes, and snippets.

@terabyte
Created June 23, 2016 01:17
Show Gist options
  • Save terabyte/ffc37a812e19b438479758244adf0cae to your computer and use it in GitHub Desktop.
Save terabyte/ffc37a812e19b438479758244adf0cae to your computer and use it in GitHub Desktop.
package com.cloudera;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import misc1.commons.ExceptionUtils;
import misc1.commons.options.OptionsFragment;
import misc1.commons.options.OptionsLibrary;
import misc1.commons.options.OptionsResults;
import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.RedirectLocations;
import org.apache.http.protocol.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import qbt.HelpTier;
import qbt.QbtCommand;
import qbt.QbtCommandName;
import qbt.QbtCommandOptions;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test extends QbtCommand<Test.Options> {
private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);
private static final String ETAG_HEADER_NAME = "ETag";
private static final Pattern PARENT_DIR_REGEX = Pattern.compile(".*<a.*[Hh][Rr][Ee][Ff]=\"[^\"]+\".*>Parent Directory</a>.*");
private static final Pattern FILENAME_REGEX = Pattern.compile(".*<a.*[Hh][Rr][Ee][Ff]=\"([^\"]+)\".*>\\1</a>.*");
private static final String MISSING_ETAG_STR = "MISSING ETAG: ";
private static final String MISMATCH_ETAG_STR = "DIFFERENT CONTENT: ";
private static final String SRC_ONLY_STR = "SOURCE ONLY: ";
private static final String DEST_ONLY_STR = "DESTINATION ONLY: ";
private static final String DEFAULT_TIMEOUT = "86400"; // 1 day
private static final Integer EXECUTOR_SERVICE_TIMEOUT_MILLIS = 1000;
@QbtCommandName("test")
public static interface Options extends QbtCommandOptions {
}
@Override
public Class<Options> getOptionsClass() {
return Options.class;
}
@Override
public HelpTier getHelpTier() {
return HelpTier.COMMON;
}
@Override
public String getDescription() {
return "Compare two URLs contents";
}
@Override
public int run(OptionsResults<? extends Options> options) throws IOException {
try (CloseableHttpClient hc = HttpClients.createDefault()) {
LinkedList<CloseableHttpResponse> hoard = new LinkedList<>();
int count = 0;
while(true) {
HttpGet get = new HttpGet("http://www.google.com");
hoard.add(hc.execute(get));
LOGGER.info("Hoard size: " + hoard.size());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment