Search in sources :

Example 16 with GetResult

use of com.couchbase.client.java.kv.GetResult in project connectors-se by Talend.

the class StringParser method parse.

@Override
public Record parse(Collection collection, String id) {
    GetResult result;
    try {
        result = collection.get(id, GetOptions.getOptions().transcoder(RawStringTranscoder.INSTANCE));
    } catch (CouchbaseException e) {
        LOG.error(e.getMessage());
        throw new ComponentException(e.getMessage());
    }
    String data = result.contentAs(String.class);
    final Record.Builder recordBuilder = builderFactory.newRecordBuilder(schemaStringDocument);
    recordBuilder.withString("id", id);
    recordBuilder.withString("content", data);
    return recordBuilder.build();
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) GetResult(com.couchbase.client.java.kv.GetResult) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Record(org.talend.sdk.component.api.record.Record)

Example 17 with GetResult

use of com.couchbase.client.java.kv.GetResult in project connectors-se by Talend.

the class CouchbaseOutputTest method outputBinaryTest.

@Test
@DisplayName("Check binary document output")
void outputBinaryTest() {
    log.info("Test start: outputBinaryTest");
    String idPrefix = "outputBinaryDocumentTest";
    String docContent = "DocumentContent";
    int docCount = 2;
    List<Record> records = new ArrayList<>();
    final Schema.Entry.Builder entryBuilder = recordBuilderFactory.newEntryBuilder();
    for (int i = 0; i < docCount; i++) {
        Record record = recordBuilderFactory.newRecordBuilder().withString(entryBuilder.withName("id").withType(Schema.Type.STRING).build(), generateDocId(idPrefix, i)).withBytes(entryBuilder.withName("content").withType(Schema.Type.BYTES).build(), (docContent + "_" + i).getBytes(StandardCharsets.UTF_8)).build();
        records.add(record);
    }
    componentsHandler.setInputData(records);
    CouchbaseOutputConfiguration configuration = getOutputConfiguration();
    configuration.getDataSet().setDocumentType(DocumentType.BINARY);
    configuration.setIdFieldName("id");
    executeJob(configuration);
    Collection collection = couchbaseCluster.bucket(BUCKET_NAME).defaultCollection();
    List<GetResult> resultList = new ArrayList<>();
    for (int i = 0; i < docCount; i++) {
        GetResult result = collection.get(generateDocId(idPrefix, i), GetOptions.getOptions().transcoder(RawBinaryTranscoder.INSTANCE));
        resultList.add(result);
    }
    assertEquals(2, resultList.size());
    for (int i = 0; i < docCount; i++) {
        GetResult getResult = resultList.get(i);
        byte[] data = getResult.contentAs(byte[].class);
        assertArrayEquals((docContent + "_" + i).getBytes(StandardCharsets.UTF_8), data);
    }
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) ArrayList(java.util.ArrayList) Collection(com.couchbase.client.java.Collection) Record(org.talend.sdk.component.api.record.Record) Test(org.junit.jupiter.api.Test) CouchbaseUtilTest(org.talend.components.couchbase.CouchbaseUtilTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 18 with GetResult

use of com.couchbase.client.java.kv.GetResult in project ShedLock by lukas-krecan.

the class CouchbaseLockProviderIntegrationTest method assertUnlocked.

@Override
public void assertUnlocked(String lockName) {
    GetResult result = bucket.defaultCollection().get(lockName);
    JsonObject lockDocument = result.contentAsObject();
    assertThat(parse((String) lockDocument.get(LOCK_UNTIL))).isBeforeOrEqualTo(now());
    assertThat(parse((String) lockDocument.get(LOCKED_AT))).isBefore(now());
    assertThat(lockDocument.get(LOCKED_BY)).asString().isNotEmpty();
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject)

Example 19 with GetResult

use of com.couchbase.client.java.kv.GetResult in project spring-data-couchbase by spring-projects.

the class CustomTypeKeyIntegrationTests method saveSimpleEntityCorrectlyWithDifferentTypeKey.

@Test
void saveSimpleEntityCorrectlyWithDifferentTypeKey() {
    clientFactory.getBucket().waitUntilReady(Duration.ofSeconds(10));
    User user = new User(UUID.randomUUID().toString(), "firstname", "lastname");
    // When using 'mocked', this call runs fine when the test class is ran by itself,
    // but it times-out when ran together with all the tests under
    // org.springframework.data.couchbase
    User modified = operations.upsertById(User.class).one(user);
    assertEquals(user, modified);
    GetResult getResult = clientFactory.getCollection(null).get(user.getId());
    assertEquals("abstractuser", getResult.contentAsObject().getString(CUSTOM_TYPE_KEY));
    assertFalse(getResult.contentAsObject().containsKey(DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY));
    operations.removeById(User.class).one(user.getId());
}
Also used : User(org.springframework.data.couchbase.domain.User) GetResult(com.couchbase.client.java.kv.GetResult) Test(org.junit.jupiter.api.Test)

Example 20 with GetResult

use of com.couchbase.client.java.kv.GetResult in project spring-data-couchbase by spring-projects.

the class CouchbaseRepositoryQueryIntegrationTests method annotatedFieldFindName.

@Test
void annotatedFieldFindName() {
    Person person = null;
    try {
        person = new Person(1, "first", "last");
        // salutation is stored as prefix
        person.setSalutation("Mrs");
        personRepository.save(person);
        GetResult result = couchbaseTemplate.getCouchbaseClientFactory().getBucket().defaultCollection().get(person.getId().toString());
        assertEquals(person.getSalutation(), result.contentAsObject().get("prefix"));
        Person person2 = personRepository.findById(person.getId().toString()).get();
        assertEquals(person.getSalutation(), person2.getSalutation());
        List<Person> persons3 = personRepository.findBySalutation("Mrs");
        assertEquals(1, persons3.size());
        assertEquals(person.getSalutation(), persons3.get(0).getSalutation());
    } finally {
        personRepository.deleteById(person.getId().toString());
    }
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) Person(org.springframework.data.couchbase.domain.Person) AirportRepositoryScanConsistencyTest(org.springframework.data.couchbase.domain.AirportRepositoryScanConsistencyTest) Test(org.junit.jupiter.api.Test)

Aggregations

GetResult (com.couchbase.client.java.kv.GetResult)39 Test (org.junit.jupiter.api.Test)25 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)20 JsonObject (com.couchbase.client.java.json.JsonObject)18 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)15 MutationResult (com.couchbase.client.java.kv.MutationResult)11 Collection (com.couchbase.client.java.Collection)7 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)6 Bucket (com.couchbase.client.java.Bucket)5 Cluster (com.couchbase.client.java.Cluster)4 Record (org.talend.sdk.component.api.record.Record)4 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)3 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)3 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)2 TimeoutException (com.couchbase.client.core.error.TimeoutException)2 JsonArray (com.couchbase.client.java.json.JsonArray)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2