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();
}
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);
}
}
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();
}
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());
}
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());
}
}
Aggregations