use of com.google.common.primitives.Ints in project divolte-collector by divolte.
the class AsyncRequestBodyReceiver method receive.
public void receive(final BiConsumer<InputStream, Integer> callback, final HttpServerExchange exchange) {
Objects.requireNonNull(callback);
if (logger.isDebugEnabled()) {
logger.debug("Pre-allocating buffer with {} chunks.", preallocateChunks.get());
}
if (exchange.isRequestComplete()) {
logger.debug("Request already completed; zero length content body.");
callback.accept(EMPTY_INPUT_STREAM, 0);
return;
}
// Determine the number of buffer-slots to use, trusting a well-formed content-length
// header if that's present.
final Optional<Integer> contentLength = Optional.ofNullable(exchange.getRequestHeaders().getFirst(Headers.CONTENT_LENGTH)).map(Ints::tryParse);
if (logger.isDebugEnabled()) {
logger.debug("Content length claimed by request: {}", contentLength);
}
final int provisionChunks = contentLength.map(AsyncRequestBodyReceiver::calculateChunks).orElseGet(preallocateChunks::get);
if (provisionChunks > maximumChunks) {
logger.info("Rejecting request; anticipated content length ({}) will exceed exceed maximum allowed {})", contentLength, maximumChunks * ChunkyByteBuffer.CHUNK_SIZE);
rejectLargeRequest(exchange);
return;
}
// If we've reached this point we're always going to accept the body, so continuing is fine.
if (HttpContinue.requiresContinueResponse(exchange)) {
logger.debug("Request requires permission to proceed; allowing to continue.");
HttpContinue.sendContinueResponse(exchange, new IoCallback() {
@Override
public void onComplete(final HttpServerExchange exchange, final Sender sender) {
receive(callback, exchange, contentLength, provisionChunks);
}
@Override
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) {
logger.error("Error allowing request to continue.");
exchange.endExchange();
}
});
} else {
receive(callback, exchange, contentLength, provisionChunks);
}
}
use of com.google.common.primitives.Ints in project divolte-collector by divolte.
the class SeleniumTestBase method setupSauceLabs.
private void setupSauceLabs() throws MalformedURLException {
final String sauceUserName = Optional.ofNullable(System.getenv(SAUCE_USER_NAME_ENV_VAR)).orElseThrow(() -> new RuntimeException("When using 'sauce' as Selenium driver, please set the SauceLabs username " + "in the " + SAUCE_USER_NAME_ENV_VAR + " env var."));
final String sauceApiKey = Optional.ofNullable(System.getenv(SAUCE_API_KEY_ENV_VAR)).orElseThrow(() -> new RuntimeException("When using 'sauce' as Selenium driver, please set the SauceLabs username " + "in the " + SAUCE_API_KEY_ENV_VAR + " env var."));
final String sauceHost = Optional.ofNullable(System.getenv(SAUCE_HOST_ENV_VAR)).orElse("localhost");
final int saucePort = Optional.ofNullable(System.getenv(SAUCE_PORT_ENV_VAR)).map(Ints::tryParse).orElse(4445);
final DesiredCapabilities caps = capabilities.get();
// Note: getMethodName() is misleading. It's really the formatted name from the @Parameters annotation.
caps.setCapability("name", String.format("%s: %s", getClass().getSimpleName(), testName.getMethodName()));
caps.setCapability("public", "team");
caps.setCapability("videoUploadOnPass", false);
final RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL(String.format("http://%s:%s@%s:%d/wd/hub", sauceUserName, sauceApiKey, sauceHost, saucePort)), caps);
final String sauceJobId = remoteDriver.getSessionId().toString();
final SauceREST sauce = new SauceREST(sauceUserName, sauceApiKey);
driver = remoteDriver;
testResultHook = Optional.of(result -> {
switch(result) {
case Passed:
sauce.jobPassed(sauceJobId);
break;
case Skipped:
sauce.deleteJob(sauceJobId);
break;
case Failed:
sauce.jobFailed(sauceJobId);
}
});
}
Aggregations