use of com.couchbase.client.core.Core in project couchbase-jdbc-driver by couchbaselabs.
the class AnalyticsProtocol method fetchResult.
@Override
public JsonParser fetchResult(QueryServiceResponse response, SubmitStatementOptions options) throws SQLException {
int p = response.handle.lastIndexOf("/");
if (p < 0) {
throw new SQLNonTransientConnectionException("Protocol error - could not extract deferred ID");
}
String handlePath = response.handle.substring(p);
Core core = connectionHandle.core();
CoreContext ctx = core.context();
AnalyticsRequest request = new AnalyticsRequest(getTimeout(options), ctx, ctx.environment().retryStrategy(), ctx.authenticator(), null, AnalyticsRequest.NO_PRIORITY, true, UUID.randomUUID().toString(), "", null, null, null, QUERY_RESULT_ENDPOINT_PATH + handlePath, HttpMethod.GET);
core.send(request);
try {
AnalyticsResponse analyticsResponse = block(request.response());
PipedOutputStream pos = new PipedOutputStream();
InputStream is = new PipedInputStream(pos);
rowExecutor.submit(() -> {
try {
final AtomicBoolean first = new AtomicBoolean(true);
Stream<AnalyticsChunkRow> rows = analyticsResponse.rows().toStream();
pos.write('[');
rows.forEach(row -> {
try {
if (!first.compareAndSet(true, false)) {
pos.write(',');
}
pos.write(row.data());
} catch (IOException e) {
throw new RuntimeException("Failed to parse JSON row", e);
}
});
pos.write(']');
} catch (Exception e) {
throw new RuntimeException("Failure during streaming rows", e);
} finally {
try {
pos.close();
} catch (IOException e) {
// ignored.
}
}
});
return driverContext.getGenericObjectReader().getFactory().createParser(is);
} catch (JsonProcessingException e) {
throw getErrorReporter().errorInProtocol(e);
} catch (IOException e) {
throw getErrorReporter().errorInConnection(e);
} catch (Exception e) {
throw getErrorReporter().errorInConnection(e.getMessage());
}
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderIntegrationTest method openBucketFromSecondValidSeed.
/**
* Bucket config should also be loaded when the first seed in the list is not available.
*/
@Test
void openBucketFromSecondValidSeed() {
TestNodeConfig cfg = config().firstNodeWith(Services.KV).get();
Set<SeedNode> seeds = new HashSet<>(Arrays.asList(SeedNode.create("1.2.3.4"), SeedNode.create(cfg.hostname(), Optional.of(cfg.ports().get(Services.KV)), Optional.of(cfg.ports().get(Services.MANAGER)))));
SimpleEventBus eventBus = new SimpleEventBus(true);
environment = CoreEnvironment.builder().eventBus(eventBus).build();
core = Core.create(environment, authenticator(), seeds);
String bucketName = config().bucketname();
ConfigurationProvider provider = new DefaultConfigurationProvider(core, seeds);
openAndClose(bucketName, provider);
provider.shutdown().block();
waitUntilCondition(() -> eventBus.publishedEvents().stream().anyMatch(e -> e instanceof EndpointConnectionFailedEvent));
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class GlobalLoaderIntegrationTest method loadGlobalConfigViaCarrierPublication.
/**
* This is a very simplistic test that makes sure that we can "round trip" in the
* {@link GlobalLoader} by grabbing a JSON decodable config through the full stack.
*/
@Test
void loadGlobalConfigViaCarrierPublication() {
TestNodeConfig config = config().firstNodeWith(Services.KV).get();
Core core = Core.create(env, authenticator(), seedNodes());
GlobalLoader loader = new GlobalLoader(core);
ProposedGlobalConfigContext globalConfigContext = loader.load(new NodeIdentifier(config.hostname(), config.ports().get(Services.MANAGER)), config.ports().get(Services.KV)).block();
assertNotNull(globalConfigContext);
assertNotNull(globalConfigContext.config());
core.shutdown().block();
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderIntegrationTest method loadConfigViaCarrierPublication.
/**
* This is a very simplistic test that makes sure that we can "round trip" in the
* {@link KeyValueBucketLoader} by grabbing a JSON decodable config through the full stack.
*/
@Test
void loadConfigViaCarrierPublication() {
TestNodeConfig config = config().firstNodeWith(Services.KV).get();
Core core = Core.create(env, authenticator(), seedNodes());
KeyValueBucketLoader loader = new KeyValueBucketLoader(core);
ProposedBucketConfigContext loaded = loader.load(new NodeIdentifier(config.hostname(), config.ports().get(Services.MANAGER)), config.ports().get(Services.KV), config().bucketname(), Optional.empty()).block();
assertNotNull(loaded);
assertEquals(config().bucketname(), loaded.bucketName());
core.shutdown().block();
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class CoreAnalyticsLinkManager method sendLink.
private CompletableFuture<Void> sendLink(HttpMethod method, Map<String, String> link, CoreCommonOptions options, String tracingId) {
// ensure mutability, and don't modify caller's map
link = new HashMap<>(link);
CoreHttpPath path = getLinkPathAndAdjustMap(link);
UrlQueryStringBuilder form = newForm();
link.forEach(form::set);
return httpClient.newRequest(method, path, options).trace(tracingId).form(form).exec(core).exceptionally(t -> {
throw translateCompilationFailureToInvalidArgument(t);
}).thenApply(result -> null);
}
Aggregations