com.couchbase.client.java.Bucket Java Examples
The following examples show how to use
com.couchbase.client.java.Bucket.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testInputFlowFileContent() throws Exception { Bucket bucket = mock(Bucket.class); String inFileDataStr = "doc-in"; String content = "{\"key\":\"value\"}"; when(bucket.get(inFileDataStr, RawJsonDocument.class)) .thenReturn(RawJsonDocument.create(inFileDataStr, content)); setupMockBucket(bucket); byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 1); testRunner.assertTransferCount(REL_ORIGINAL, 1); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0); outFile.assertContentEquals(content); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_ORIGINAL).get(0); orgFile.assertContentEquals(inFileDataStr); }
Example #2
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testCouchbaseTempClusterError() throws Exception { String docIdExp = "doc-c"; Bucket bucket = mock(Bucket.class); CouchbaseException exception = new BackpressureException(); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenThrow(exception); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 1); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); }
Example #3
Source File: TestGetCouchbaseKey.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testDocumentNotFound() throws Exception { String docIdExp = "doc-n"; Bucket bucket = mock(Bucket.class); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenReturn(null); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 1); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_FAILURE).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), DocumentDoesNotExistException.class.getName()); }
Example #4
Source File: TestGetCouchbaseKey.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testBinaryDocument() throws Exception { Bucket bucket = mock(Bucket.class); String inFileDataStr = "doc-in"; String content = "binary"; ByteBuf buf = Unpooled.copiedBuffer(content.getBytes(StandardCharsets.UTF_8)); when(bucket.get(inFileDataStr, BinaryDocument.class)) .thenReturn(BinaryDocument.create(inFileDataStr, buf)); setupMockBucket(bucket); byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.setProperty(DOCUMENT_TYPE, DocumentType.Binary.toString()); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 1); testRunner.assertTransferCount(REL_ORIGINAL, 1); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0); outFile.assertContentEquals(content); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_ORIGINAL).get(0); orgFile.assertContentEquals(inFileDataStr); }
Example #5
Source File: TestGetCouchbaseKey.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testInputFlowFileContent() throws Exception { Bucket bucket = mock(Bucket.class); String inFileDataStr = "doc-in"; String content = "{\"key\":\"value\"}"; when(bucket.get(inFileDataStr, RawJsonDocument.class)) .thenReturn(RawJsonDocument.create(inFileDataStr, content)); setupMockBucket(bucket); byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 1); testRunner.assertTransferCount(REL_ORIGINAL, 1); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0); outFile.assertContentEquals(content); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_ORIGINAL).get(0); orgFile.assertContentEquals(inFileDataStr); }
Example #6
Source File: TestCouchbaseBucketRegistry.java From samza with Apache License 2.0 | 6 votes |
/** * This unit test uses CouchbaseBucketRegistry to register two mocked buckets with same name but in different clusters. * Calling registry.getBucket with same bucketName but different clusterNodes should return different Bucket instances. */ @Test public void testOpenSameBucketNameFromDifferentClusters() { String bucketName = "bucket"; List<String> clusterNodes1 = Arrays.asList("cluster1"); List<String> clusterNodes2 = Arrays.asList("cluster2"); CouchbaseEnvironmentConfigs configs = new CouchbaseEnvironmentConfigs(); CouchbaseCluster cluster1 = mock(CouchbaseCluster.class); CouchbaseCluster cluster2 = mock(CouchbaseCluster.class); when(cluster1.openBucket(bucketName)).thenReturn(mock(Bucket.class)); when(cluster2.openBucket(bucketName)).thenReturn(mock(Bucket.class)); mockStatic(CouchbaseCluster.class); when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes1))).thenReturn(cluster1); when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes2))).thenReturn(cluster2); CouchbaseBucketRegistry registry = new CouchbaseBucketRegistry(); Bucket bucketInCluster1 = registry.getBucket(bucketName, clusterNodes1, configs); Bucket bucketInCluster2 = registry.getBucket(bucketName, clusterNodes2, configs); assertNotEquals(bucketInCluster1, bucketInCluster2); }
Example #7
Source File: TestCouchbaseBucketRegistry.java From samza with Apache License 2.0 | 6 votes |
/** * This unit test simulates 10 tasks using the same bucket. Each task will call registry.getBucket once. Then * each task will also call registry.closeBucket once. After that, registry.closeBucket should return false if we * close the bucket one more time. And the bucket should have already been closed. */ @Test public void testCloseBucket() { String bucketName = "bucket"; List<String> clusterNodes = Arrays.asList("cluster"); CouchbaseEnvironmentConfigs configs = new CouchbaseEnvironmentConfigs(); CouchbaseCluster cluster = mock(CouchbaseCluster.class); Bucket bucket = mock(Bucket.class); when(bucket.close()).thenReturn(true).thenReturn(false); when(cluster.openBucket(bucketName)).thenReturn(bucket); when(cluster.disconnect()).thenReturn(true).thenReturn(false); mockStatic(CouchbaseCluster.class); when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes))).thenReturn(cluster); CouchbaseBucketRegistry registry = new CouchbaseBucketRegistry(); int numOfThreads = 10; for (int i = 0; i < numOfThreads; i++) { registry.getBucket(bucketName, clusterNodes, configs); } for (int i = 0; i < numOfThreads; i++) { assertTrue(registry.closeBucket(bucketName, clusterNodes)); } // Close one more time. Should return false. assertFalse(registry.closeBucket(bucketName, clusterNodes)); // Bucket should has been closed assertFalse(bucket.close()); }
Example #8
Source File: N1QLLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void givenSelectStatementWithDSL2_whenQuery_thenResult() { Bucket bucket = bucketFactory.getTravelSampleBucket(); Statement st2 = select( x("t.city, t.airportname") .concat(s(" (")).concat(x("t.faa")).concat(s(")")).as("portname_faa")) .from(i("travel-sample").as("t")) .where( x("t.type").eq(s("airport")) .and(x("t.country").like(s("%States"))) .and(x("t.geo.lat").gte(70))) .limit(2); N1qlQueryResult r5 = bucket.query(N1qlQuery.simple(st2)); List<JsonNode> list5 = extractJsonResult(r5); System.out.println("First Doc : " + list5.get(0)); System.out.println("Query from Statement2: " + st2.toString()); }
Example #9
Source File: TestGetCouchbaseKey.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testDocIdExp() throws Exception { String docIdExp = "${'someProperty'}"; String somePropertyValue = "doc-p"; Bucket bucket = mock(Bucket.class); String content = "{\"key\":\"value\"}"; when(bucket.get(somePropertyValue, RawJsonDocument.class)) .thenReturn(RawJsonDocument.create(somePropertyValue, content)); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); byte[] inFileData = "input FlowFile data".getBytes(StandardCharsets.UTF_8); Map<String, String> properties = new HashMap<>(); properties.put("someProperty", somePropertyValue); testRunner.enqueue(inFileData, properties); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 1); testRunner.assertTransferCount(REL_ORIGINAL, 1); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0); outFile.assertContentEquals(content); }
Example #10
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testCouchbaseInvalidInputError() throws Exception { String docIdExp = "doc-c"; Bucket bucket = mock(Bucket.class); CouchbaseException exception = new RequestTooBigException(); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenThrow(exception); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 1); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_FAILURE).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); }
Example #11
Source File: CouchbaseInputTestIT.java From components with Apache License 2.0 | 6 votes |
private void populateBucket() { CouchbaseEnvironment env = DefaultCouchbaseEnvironment .builder() .socketConnectTimeout(60000) .connectTimeout(60000) .keepAliveInterval(60000) .keyValueServiceConfig(KeyValueServiceConfig.create(60)) // If skip this config, we may get TimeoutException https://forums.couchbase.com/t/kv-upsert-throwing-timeoutexception-couchbase-4-5/9399 .build(); CouchbaseCluster cluster = CouchbaseCluster.create(env, bootstrapNodes); Bucket bucket = cluster.openBucket(bucketName, password); LOGGER.info("Connected to bucket - " + bucketName); assertTrue(bucket.bucketManager().flush()); JsonDocument document = JsonDocument.create("foo", JsonObject.create().put("bar", 42)); bucket.upsert(document, PersistTo.MASTER); bucket.close(); LOGGER.info("Bucket is closed after upserting data"); if (cluster != null) { cluster.disconnect(); } }
Example #12
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testBinaryDocumentToAttribute() throws Exception { Bucket bucket = mock(Bucket.class); String inFileDataStr = "doc-in"; String content = "binary"; ByteBuf buf = Unpooled.copiedBuffer(content.getBytes(StandardCharsets.UTF_8)); when(bucket.get(inFileDataStr, BinaryDocument.class)) .thenReturn(BinaryDocument.create(inFileDataStr, buf)); setupMockBucket(bucket); byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.setProperty(DOCUMENT_TYPE, DocumentType.Binary.toString()); testRunner.setProperty(PUT_VALUE_TO_ATTRIBUTE, "targetAttribute"); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 1); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0); outFile.assertContentEquals(inFileDataStr); outFile.assertAttributeEquals("targetAttribute", "binary"); }
Example #13
Source File: TestGetCouchbaseKey.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testCouchbaseTempClusterError() throws Exception { String docIdExp = "doc-c"; Bucket bucket = mock(Bucket.class); CouchbaseException exception = new BackpressureException(); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenThrow(exception); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 1); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); }
Example #14
Source File: TestGetCouchbaseKey.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testCouchbaseTempFlowFileError() throws Exception { String docIdExp = "doc-c"; Bucket bucket = mock(Bucket.class); // There is no suitable CouchbaseException for temp flowfile error, currently. CouchbaseException exception = new DurabilityException(); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenThrow(exception); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 1); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); }
Example #15
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testCouchbaseFatalError() throws Exception { String docIdExp = "doc-c"; Bucket bucket = mock(Bucket.class); CouchbaseException exception = new NotConnectedException(); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenThrow(exception); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 1); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); }
Example #16
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testBinaryDocument() throws Exception { Bucket bucket = mock(Bucket.class); String inFileDataStr = "doc-in"; String content = "binary"; ByteBuf buf = Unpooled.copiedBuffer(content.getBytes(StandardCharsets.UTF_8)); when(bucket.get(inFileDataStr, BinaryDocument.class)) .thenReturn(BinaryDocument.create(inFileDataStr, buf)); setupMockBucket(bucket); byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.setProperty(DOCUMENT_TYPE, DocumentType.Binary.toString()); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 1); testRunner.assertTransferCount(REL_ORIGINAL, 1); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0); outFile.assertContentEquals(content); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_ORIGINAL).get(0); orgFile.assertContentEquals(inFileDataStr); }
Example #17
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testDocIdExpWithInvalidExpression() throws Exception { String docIdExp = "${nonExistingFunction('doc-s')}"; String docId = "doc-s"; Bucket bucket = mock(Bucket.class); String content = "{\"key\":\"value\"}"; when(bucket.get(docId, RawJsonDocument.class)) .thenReturn(RawJsonDocument.create(docId, content)); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); testRunner.enqueue(new byte[0]); try { testRunner.run(); fail("Exception should be thrown."); } catch (AssertionError e) { Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class)); } testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_FAILURE, 0); }
Example #18
Source File: N1QLLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDocuments_whenBatchInsert_thenResult() { Bucket bucket = bucketFactory.getTravelSampleBucket(); List<JsonDocument> documents = IntStream.rangeClosed(0,10) .mapToObj( i -> { JsonObject content = JsonObject.create() .put("id", i) .put("type", "airline") .put("name", "Sample Airline " + i); return JsonDocument.create("cust_" + i, content); }) .collect(Collectors.toList()); List<JsonDocument> r5 = Observable .from(documents) .flatMap(doc -> bucket.async().insert(doc)) .toList() .last() .toBlocking() .single(); r5.forEach(System.out::println); }
Example #19
Source File: N1QLLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenUpdateStatement_whenQuery_thenUpdate() { Bucket bucket = bucketFactory.getTravelSampleBucket(); String query2 = "UPDATE `travel-sample` USE KEYS \"cust_1\" " + "SET name=\"Sample Airline Updated\" RETURNING name"; N1qlQueryResult result = bucket.query(N1qlQuery.simple(query2)); result.forEach(System.out::println); }
Example #20
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testCouchbaseTempFlowFileError() throws Exception { String docIdExp = "doc-c"; Bucket bucket = mock(Bucket.class); // There is no suitable CouchbaseException for temp flowfile error, currently. CouchbaseException exception = new DurabilityException(); when(bucket.get(docIdExp, RawJsonDocument.class)) .thenThrow(exception); setupMockBucket(bucket); testRunner.setProperty(DOC_ID, docIdExp); String inputFileDataStr = "input FlowFile data"; byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); testRunner.enqueue(inFileData); testRunner.run(); testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_RETRY, 1); testRunner.assertTransferCount(REL_FAILURE, 0); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0); orgFile.assertContentEquals(inputFileDataStr); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); Assert.assertEquals(true, orgFile.isPenalized()); }
Example #21
Source File: CouchbaseUtils.java From nifi with Apache License 2.0 | 5 votes |
/** * A convenient method to retrieve String value when Document type is unknown. * This method uses LegacyDocument to get, then tries to convert content based on its class. * @param bucket the bucket to get a document * @param id the id of the target document * @return String representation of the stored value, or null if not found */ public static String getStringContent(Bucket bucket, String id) { final LegacyDocument doc = bucket.get(LegacyDocument.create(id)); if (doc == null) { return null; } final Object content = doc.content(); return getStringContent(content); }
Example #22
Source File: TestPutCouchbaseKey.java From nifi with Apache License 2.0 | 5 votes |
private void setupMockBucket(Bucket bucket) throws InitializationException { CouchbaseClusterControllerService service = mock(CouchbaseClusterControllerService.class); when(service.getIdentifier()).thenReturn(SERVICE_ID); when(service.openBucket(anyString())).thenReturn(bucket); when(bucket.name()).thenReturn("bucket-1"); testRunner.addControllerService(SERVICE_ID, service); testRunner.enableControllerService(service); testRunner.setProperty(COUCHBASE_CLUSTER_SERVICE, SERVICE_ID); }
Example #23
Source File: TestCouchbaseTableWriteFunction.java From samza with Apache License 2.0 | 5 votes |
@Test public void testPutAsyncException() { String key = "throwExceptionKey"; JsonObject value = JsonObject.create(); Bucket bucket = mock(Bucket.class); AsyncBucket asyncBucket = mock(AsyncBucket.class); CouchbaseTableWriteFunction<JsonObject> writeFunction = createAndInit(bucket, asyncBucket); when(asyncBucket.upsert(any(Document.class), anyLong(), any(TimeUnit.class))).thenReturn( Observable.error(new CouchbaseException())); assertTrue(writeFunction.putAsync(key, value).isCompletedExceptionally()); }
Example #24
Source File: TestCouchbaseTableReadFunction.java From samza with Apache License 2.0 | 5 votes |
@Test public void testGetAsyncStringValue() throws Exception { String key = "key"; String value = "value"; StringSerde stringSerde = new StringSerde(); Bucket bucket = mock(Bucket.class); AsyncBucket asyncBucket = mock(AsyncBucket.class); CouchbaseTableReadFunction readFunction = createAndInit(String.class, stringSerde, bucket, asyncBucket); when(asyncBucket.get(eq(key), anyObject(), anyLong(), any(TimeUnit.class))).thenReturn( Observable.just(BinaryDocument.create(key, Unpooled.wrappedBuffer(stringSerde.toBytes(value))))); assertEquals(value, readFunction.getAsync(key).get()); }
Example #25
Source File: CodeSnippets.java From tutorials with MIT License | 5 votes |
static JsonDocument getFirstFromReplicaExample(Bucket bucket, String id) { try { return bucket.get(id); } catch (CouchbaseException e) { List<JsonDocument> list = bucket.getFromReplica(id, ReplicaMode.FIRST); if (!list.isEmpty()) { return list.get(0); } } return null; }
Example #26
Source File: TestCouchbaseTableReadFunction.java From samza with Apache License 2.0 | 5 votes |
@Test public void testGetAsyncFailedToDeserialize() { String key = "key"; Bucket bucket = mock(Bucket.class); AsyncBucket asyncBucket = mock(AsyncBucket.class); CouchbaseTableReadFunction readFunction = createAndInit(String.class, new StringSerde(), bucket, asyncBucket); when(asyncBucket.get(eq(key), anyObject(), anyLong(), any(TimeUnit.class))).thenReturn( Observable.just(BinaryDocument.create(key, null))); assertTrue(readFunction.getAsync(key).isCompletedExceptionally()); }
Example #27
Source File: TestCouchbaseTableReadFunction.java From samza with Apache License 2.0 | 5 votes |
@Test public void testGetAsyncException() { String key = "throwExceptionKey"; Bucket bucket = mock(Bucket.class); AsyncBucket asyncBucket = mock(AsyncBucket.class); CouchbaseTableReadFunction readFunction = createAndInit(bucket, asyncBucket); when(asyncBucket.get(eq(key), anyObject(), anyLong(), any(TimeUnit.class))).thenReturn( Observable.error(new CouchbaseException())); assertTrue(readFunction.getAsync(key).isCompletedExceptionally()); }
Example #28
Source File: N1QLLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenSelectDSL_whenQuery_thenResult() { Bucket bucket = bucketFactory.getTravelSampleBucket(); Statement statement = select("*") .from(i("travel-sample")) .where(x("type").eq(s("airport"))) .limit(100); N1qlQueryResult r3 = bucket.query(N1qlQuery.simple(statement)); List<JsonNode> list2 = extractJsonResult(r3); System.out.println("First Airport Name: " + list2.get(0).get("travel-sample").get("airportname").asText()); }
Example #29
Source File: TestCouchbaseTableWriteFunction.java From samza with Apache License 2.0 | 5 votes |
@Test public void testPutAsyncJsonObjectValue() throws Exception { String key = "key"; JsonObject value = JsonObject.fromJson("{\"id\": 1}"); Bucket bucket = mock(Bucket.class); AsyncBucket asyncBucket = mock(AsyncBucket.class); CouchbaseTableWriteFunction<JsonObject> writeFunction = createAndInit(bucket, asyncBucket); when(asyncBucket.upsert(any(Document.class), anyLong(), any(TimeUnit.class))).thenReturn(Observable.just(null)); assertNull(writeFunction.putAsync(key, value).get()); }
Example #30
Source File: TestGetCouchbaseKey.java From nifi with Apache License 2.0 | 5 votes |
private void setupMockBucket(Bucket bucket) throws InitializationException { CouchbaseClusterControllerService service = mock(CouchbaseClusterControllerService.class); when(service.getIdentifier()).thenReturn(SERVICE_ID); when(service.openBucket(anyString())).thenReturn(bucket); when(bucket.name()).thenReturn("bucket-1"); testRunner.addControllerService(SERVICE_ID, service); testRunner.enableControllerService(service); testRunner.setProperty(COUCHBASE_CLUSTER_SERVICE, SERVICE_ID); }