private RemoteScrollableHitSource sourceWithMockedClient(
      boolean mockRemoteVersion, CloseableHttpAsyncClient httpClient) throws Exception {
    HttpAsyncClientBuilder clientBuilder = mock(HttpAsyncClientBuilder.class);
    when(clientBuilder.build()).thenReturn(httpClient);

    RestClient restClient =
        RestClient.builder(new HttpHost("localhost", 9200))
            .setHttpClientConfigCallback(httpClientBuilder -> clientBuilder)
            .build();

    TestRemoteScrollableHitSource hitSource =
        new TestRemoteScrollableHitSource(restClient) {
          @Override
          void lookupRemoteVersion(Consumer<Version> onVersion) {
            if (mockRemoteVersion) {
              onVersion.accept(Version.CURRENT);
            } else {
              super.lookupRemoteVersion(onVersion);
            }
          }
        };
    if (mockRemoteVersion) {
      hitSource.remoteVersion = Version.CURRENT;
    }
    return hitSource;
  }
Esempio n. 2
0
  public static void refresh() {
    // Load timeouts
    Object connectionTimeout = Options.getOption(Option.CONNECTION_TIMEOUT);
    if (connectionTimeout == null) connectionTimeout = CONNECTION_TIMEOUT;
    Object socketTimeout = Options.getOption(Option.SOCKET_TIMEOUT);
    if (socketTimeout == null) socketTimeout = SOCKET_TIMEOUT;

    // Create common default configuration
    RequestConfig clientConfig =
        RequestConfig.custom()
            .setConnectTimeout(((Long) connectionTimeout).intValue())
            .setSocketTimeout(((Long) socketTimeout).intValue())
            .build();

    // Create clients
    setOption(
        Option.HTTPCLIENT,
        HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).build());

    CloseableHttpAsyncClient asyncClient =
        HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).build();
    asyncClient.start();

    setOption(Option.ASYNCHTTPCLIENT, asyncClient);
  }
Esempio n. 3
0
  /**
   * Create Olingo2 Application with custom HTTP client builder.
   *
   * @param serviceUri Service Application base URI.
   * @param builder custom HTTP client builder.
   */
  public Olingo2AppImpl(String serviceUri, HttpAsyncClientBuilder builder) {
    setServiceUri(serviceUri);

    if (builder == null) {
      this.client = HttpAsyncClients.createDefault();
    } else {
      this.client = builder.build();
    }
    this.client.start();
    this.contentType = ContentType.create("application/json", Consts.UTF_8);
  }
Esempio n. 4
0
  static {
    RequestConfig clientConfig =
        RequestConfig.custom()
            .setConnectTimeout(CONNECTION_TIMEOUT)
            .setSocketTimeout(SOCKET_TIMEOUT)
            .build();

    setOption(
        Option.HTTPCLIENT,
        HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).build());

    CloseableHttpAsyncClient asyncClient =
        HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).build();
    asyncClient.start();

    setOption(Option.ASYNCHTTPCLIENT, asyncClient);
  }