本文整理汇总了Java中com.couchbase.client.java.AsyncBucket类的典型用法代码示例。如果您正苦于以下问题:Java AsyncBucket类的具体用法?Java AsyncBucket怎么用?Java AsyncBucket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncBucket类属于com.couchbase.client.java包,在下文中一共展示了AsyncBucket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getById
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes" })
@Test
public void getById() throws Exception {
Class entityClass = Entity.class;
Long id = 7L;
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class)
.expect(unit -> {
AsyncRepository repo = unit.get(AsyncRepository.class);
expect(repo.get(N1Q.qualifyId(entityClass, id), entityClass))
.andReturn(document(new Entity(id)));
})
.run(unit -> {
Entity e = (Entity) new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.get(entityClass, id)
.toBlocking()
.single();
assertNotNull(e);
assertEquals(id, e.id);
});
}
示例2: getFromReplica
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes" })
@Test
public void getFromReplica() throws Exception {
Class entityClass = Entity.class;
Long id = 7L;
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class)
.expect(unit -> {
AsyncRepository repo = unit.get(AsyncRepository.class);
expect(
repo.getFromReplica(N1Q.qualifyId(entityClass, id), ReplicaMode.FIRST, entityClass))
.andReturn(document(new Entity(id)));
})
.run(unit -> {
Entity e = (Entity) new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.getFromReplica(entityClass, id, ReplicaMode.FIRST)
.toBlocking()
.single();
assertNotNull(e);
assertEquals(id, e.id);
});
}
示例3: getAndTouch
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes" })
@Test
public void getAndTouch() throws Exception {
Class entityClass = Entity.class;
Long id = 7L;
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class)
.expect(unit -> {
AsyncRepository repo = unit.get(AsyncRepository.class);
expect(repo.getAndTouch(N1Q.qualifyId(entityClass, id), 5, entityClass))
.andReturn(document(new Entity(id)));
})
.run(unit -> {
Entity e = (Entity) new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.getAndTouch(entityClass, id, 5)
.toBlocking()
.single();
assertNotNull(e);
assertEquals(id, e.id);
});
}
示例4: getAndLock
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes" })
@Test
public void getAndLock() throws Exception {
Class entityClass = Entity.class;
Long id = 7L;
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class)
.expect(unit -> {
AsyncRepository repo = unit.get(AsyncRepository.class);
expect(repo.getAndLock(N1Q.qualifyId(entityClass, id), 5, entityClass))
.andReturn(document(new Entity(id)));
})
.run(unit -> {
Entity e = (Entity) new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.getAndLock(entityClass, id, 5)
.toBlocking()
.single();
assertNotNull(e);
assertEquals(id, e.id);
});
}
示例5: queryFailure
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test(expected = QueryExecutionException.class)
public void queryFailure() throws Exception {
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
N1qlQuery.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors())
.andReturn(Observable.just(JsonObject.create().put("foo", "bar")));
expect(result.finalSuccess()).andReturn(Observable.just(false));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.get(N1qlQuery.class))).andReturn(Observable.just(result));
})
.run(unit -> {
new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(N1qlQuery.class))
.toBlocking()
.single();
});
}
示例6: queryFailureNoError
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test(expected = QueryExecutionException.class)
public void queryFailureNoError() throws Exception {
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
N1qlQuery.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors()).andReturn(Observable.empty());
expect(result.finalSuccess()).andReturn(Observable.just(false));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.get(N1qlQuery.class))).andReturn(Observable.just(result));
})
.run(unit -> {
new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(N1qlQuery.class))
.toBlocking()
.single();
});
}
示例7: openBucket
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
private Single<SharedResource<AsyncBucket>> openBucket() {
return vertx.rxExecuteBlocking(fut -> {
SharedResources sharedResources = SharedResources.INSTANCE;
SharedResource<AsyncBucket> asyncBucket = sharedResources.getOrCreate("commentsBucket", () -> {
return couchbaseCluster.get().openBucket("album-comments").toSingle().toBlocking().value();
}, bucket -> {
bucket.close().toSingle().toBlocking().value();
});
fut.complete(asyncBucket);
});
}
示例8: AsyncDatastoreImpl
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
public AsyncDatastoreImpl(final AsyncBucket bucket, final AsyncRepository repo,
final Function<Object, Object> idGen, final JacksonMapper converter) {
this.bucket = bucket;
this.repo = repo;
this.idGen = idGen;
this.converter = converter;
}
示例9: openBucket
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
private Block openBucket(final String name, final String password, final boolean goasync) {
return unit -> {
Bucket bucket = unit.mock(Bucket.class);
unit.registerMock(Bucket.class, bucket);
if (goasync) {
AsyncBucket asyncBucket = unit.mock(AsyncBucket.class);
unit.registerMock(AsyncBucket.class, asyncBucket);
expect(bucket.async()).andReturn(asyncBucket);
}
CouchbaseCluster cluster = unit.get(CouchbaseCluster.class);
expect(cluster.openBucket(name, password)).andReturn(bucket);
};
}
示例10: query
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test
public void query() throws Exception {
byte[] bytes = ("{\"class\": \"" + Entity.class.getName()
+ "\",id: 1}").getBytes(StandardCharsets.UTF_8);
Entity entity = new Entity(1);
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
N1qlQuery.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
JacksonMapper mapper = unit.get(JacksonMapper.class);
expect(mapper.fromBytes(bytes)).andReturn(entity);
})
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
expect(row.byteValue()).andReturn(bytes);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors()).andReturn(Observable.empty());
expect(result.finalSuccess()).andReturn(Observable.just(true));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.get(N1qlQuery.class))).andReturn(Observable.just(result));
})
.run(unit -> {
List<Entity> entities = new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(N1qlQuery.class))
.toBlocking()
.single();
assertNotNull(entities);
assertEquals(entity, entities.get(0));
});
}
示例11: queryStmt
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test
public void queryStmt() throws Exception {
byte[] bytes = ("{\"class\": \"" + Entity.class.getName()
+ "\",id: 1}").getBytes(StandardCharsets.UTF_8);
Entity entity = new Entity(1);
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
Statement.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
JacksonMapper mapper = unit.get(JacksonMapper.class);
expect(mapper.fromBytes(bytes)).andReturn(entity);
})
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
expect(row.byteValue()).andReturn(bytes);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors()).andReturn(Observable.empty());
expect(result.finalSuccess()).andReturn(Observable.just(true));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.capture(N1qlQuery.class)))
.andReturn(Observable.just(result));
})
.run(unit -> {
List<Entity> entities = new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(Statement.class))
.toBlocking()
.single();
assertNotNull(entities);
assertEquals(entity, entities.get(0));
});
}
示例12: queryMappingFaiulre
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test(expected = QueryExecutionException.class)
public void queryMappingFaiulre() throws Exception {
byte[] bytes = ("{\"class\": \"" + Entity.class.getName()
+ "\",id: 1}").getBytes(StandardCharsets.UTF_8);
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
N1qlQuery.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
JacksonMapper mapper = unit.get(JacksonMapper.class);
expect(mapper.fromBytes(bytes)).andThrow(new IOException("intentional err"));
})
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
expect(row.byteValue()).andReturn(bytes);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors()).andReturn(Observable.empty());
expect(result.finalSuccess()).andReturn(Observable.just(true));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.get(N1qlQuery.class))).andReturn(Observable.just(result));
})
.run(unit -> {
new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(N1qlQuery.class))
.toBlocking()
.single();
});
}
示例13: AddAlbumCommentHandler
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
public AddAlbumCommentHandler(AsyncBucket albumCommentsBucket) {
this.albumCommentsBucket = albumCommentsBucket;
}
示例14: AjaxAlbumCommentsHandler
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
public AjaxAlbumCommentsHandler(AsyncBucket albumCommentsBucket, Properties couchbaseQueries, FreeMarkerTemplateEngine templateEngine) {
this.albumCommentsBucket = albumCommentsBucket;
this.findRecentCommentsByAlbum = couchbaseQueries.getProperty("findRecentCommentsByAlbum");
this.templateEngine = templateEngine;
}
示例15: runAsync
import com.couchbase.client.java.AsyncBucket; //导入依赖的package包/类
private <R> R runAsync(Function<AsyncBucket, Observable<R>> function) {
return single(function.apply(bucket.async())
.retryWhen(getRetryStrategy()));
}