List of usage examples for io.netty.util CharsetUtil UTF_8
Charset UTF_8
To view the source code for io.netty.util CharsetUtil UTF_8.
Click Source Link
From source file:com.couchbase.client.core.cluster.BinaryMessageTest.java
License:Open Source License
@Test public void shouldRemoveDocumentWithCAS() { String key = "remove-key-cas"; String content = "Hello World!"; UpsertRequest upsert = new UpsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket); UpsertResponse upsertResponse = cluster.<UpsertResponse>send(upsert).toBlockingObservable().single(); assertEquals(ResponseStatus.SUCCESS, upsertResponse.status()); RemoveRequest remove = new RemoveRequest(key, 1233443, bucket); assertEquals(ResponseStatus.EXISTS,//from w w w. j a v a 2 s .c o m cluster.<RemoveResponse>send(remove).toBlockingObservable().single().status()); remove = new RemoveRequest(key, upsertResponse.cas(), bucket); assertEquals(ResponseStatus.SUCCESS, cluster.<RemoveResponse>send(remove).toBlockingObservable().single().status()); }
From source file:com.couchbase.client.core.cluster.DCPConnectionTest.java
License:Apache License
private void upsertKey(String key, String value) { UpsertResponse resp = cluster()//from w ww.ja v a 2s.co m .<UpsertResponse>send( new UpsertRequest(key, Unpooled.copiedBuffer(value, CharsetUtil.UTF_8), 1, 0, bucket())) .toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, resp.status()); ReferenceCountUtil.releaseLater(resp.content()); }
From source file:com.couchbase.client.core.cluster.DCPConnectionTest.java
License:Apache License
@Test public void shouldUseFlowControl() throws InterruptedException { final String fooValue = "shouldUseFlowControl---foo-value"; final String barValue = "shouldUseFlowControl---bar-value"; final DCPConnection connection = createConnection("shouldUseFlowControl"); List<MutationToken> state = connection.getCurrentState().toList().toBlocking().single(); assertEquals(numberOfPartitions(), state.size()); for (MutationToken token : state) { connection.addStream((short) token.vbucketID(), token.vbucketUUID(), token.sequenceNumber(), 0xffffffff, token.sequenceNumber(), 0xffffffff).toBlocking().single(); }/*w w w. j a v a2s .c om*/ final AtomicInteger fooMutations = new AtomicInteger(0); final AtomicInteger barMutations = new AtomicInteger(0); final CountDownLatch latch = new CountDownLatch(1); connection.subject().takeUntil(Observable.timer(10, TimeUnit.SECONDS)).subscribe(new Action1<DCPRequest>() { @Override public void call(DCPRequest request) { if (request instanceof MutationMessage) { MutationMessage mutation = (MutationMessage) request; String key = mutation.key(); if (key.equals("foo")) { assertEquals(mutation.content().toString(CharsetUtil.UTF_8), fooValue); fooMutations.incrementAndGet(); } else if (key.equals("bar")) { assertEquals(mutation.content().toString(CharsetUtil.UTF_8), barValue); barMutations.incrementAndGet(); } else { fail("unexpected mutation of key: " + key); } ReferenceCountUtil.releaseLater(((MutationMessage) request).content()); } if (request instanceof DCPMessage) { connection.consumed((DCPMessage) request); } } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { fail(throwable.toString()); } }, new Action0() { @Override public void call() { latch.countDown(); } }); for (int i = 0; i < 10; i++) { upsertKey("foo", fooValue); upsertKey("bar", barValue); } latch.await(); assertEquals(10, fooMutations.get()); assertEquals(10, barMutations.get()); }
From source file:com.couchbase.client.core.cluster.DCPMessageTest.java
License:Open Source License
@Test public void shouldRequestStream() throws Exception { List<OpenConnectionResponse> open = cluster() .<OpenConnectionResponse>send(new OpenConnectionRequest("hello", bucket())).toList().toBlocking() .single();//from w w w .j a v a 2 s . co m assertEquals(1, open.size()); for (OpenConnectionResponse response : open) { assertEquals(ResponseStatus.SUCCESS, response.status()); } StreamRequestResponse addStream = cluster() .<StreamRequestResponse>send(new StreamRequestRequest(calculateVBucketForKey("foo"), bucket())) .toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, addStream.status()); TestSubscriber<DCPRequest> subscriber = new TestSubscriber<DCPRequest>(); open.get(0).connection().subject().takeUntil(Observable.timer(2, TimeUnit.SECONDS)) .subscribe((Subscriber) subscriber); UpsertResponse foo = cluster() .<UpsertResponse>send( new UpsertRequest("foo", Unpooled.copiedBuffer("bar", CharsetUtil.UTF_8), 1, 0, bucket())) .toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, foo.status()); ReferenceCountUtil.releaseLater(foo.content()); subscriber.awaitTerminalEvent(); List<DCPRequest> items = subscriber.getOnNextEvents(); boolean seenMutation = false; boolean seenSnapshot = false; for (DCPRequest found : items) { if (found instanceof SnapshotMarkerMessage) { seenSnapshot = true; } else if (found instanceof MutationMessage) { seenMutation = true; assertEquals("foo", ((MutationMessage) found).key()); ReferenceCountUtil.releaseLater(((MutationMessage) found).content()); } } assertTrue(seenMutation); assertTrue(seenSnapshot); }
From source file:com.couchbase.client.core.cluster.FlushTest.java
License:Apache License
@Test public void shouldFlush() { List<String> keys = Arrays.asList("key1", "key2", "key3"); Observable.from(keys).flatMap(new Func1<String, Observable<UpsertResponse>>() { @Override//from w w w. jav a2 s .c o m public Observable<UpsertResponse> call(String key) { return cluster().send( new UpsertRequest(key, Unpooled.copiedBuffer("Content", CharsetUtil.UTF_8), bucket())); } }).doOnNext(new Action1<UpsertResponse>() { @Override public void call(UpsertResponse upsertResponse) { ReferenceCountUtil.releaseLater(upsertResponse.content()); } }).toBlocking().last(); FlushResponse response = cluster().<FlushResponse>send(new FlushRequest(bucket(), password())).toBlocking() .single(); assertEquals(ResponseStatus.SUCCESS, response.status()); ReferenceCountUtil.releaseLater(response.content()); List<GetResponse> responses = Observable.from(keys).flatMap(new Func1<String, Observable<GetResponse>>() { @Override public Observable<GetResponse> call(String key) { return cluster().send(new GetRequest(key, bucket())); } }).toList().toBlocking().single(); assertEquals(keys.size(), responses.size()); for (GetResponse get : responses) { assertEquals(ResponseStatus.NOT_EXISTS, get.status()); ReferenceCountUtil.releaseLater(get.content()); } }
From source file:com.couchbase.client.core.cluster.KeyValueMessageTest.java
License:Apache License
@Test public void shouldUpsertAndGetDocument() throws Exception { String key = "upsert-key"; String content = "Hello World!"; UpsertRequest upsert = new UpsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket()); UpsertResponse response = cluster().<UpsertResponse>send(upsert).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertValidMetadata(response.mutationToken()); GetRequest request = new GetRequest(key, bucket()); GetResponse getResponse = cluster().<GetResponse>send(request).toBlocking().single(); assertEquals(content, getResponse.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(getResponse.content()); }
From source file:com.couchbase.client.core.cluster.KeyValueMessageTest.java
License:Apache License
@Test public void shouldUpsertWithExpiration() throws Exception { String key = "upsert-key-vanish"; String content = "Hello World!"; UpsertRequest upsert = new UpsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), 1, 0, bucket());/*from www . ja v a 2 s.c om*/ UpsertResponse response = cluster().<UpsertResponse>send(upsert).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertValidMetadata(response.mutationToken()); Thread.sleep(2000); GetRequest request = new GetRequest(key, bucket()); GetResponse getResponse = cluster().<GetResponse>send(request).toBlocking().single(); assertEquals(ResponseStatus.NOT_EXISTS, getResponse.status()); ReferenceCountUtil.releaseLater(getResponse.content()); }
From source file:com.couchbase.client.core.cluster.KeyValueMessageTest.java
License:Apache License
@Test public void shouldHandleDoubleInsert() throws Exception { String key = "insert-key"; String content = "Hello World!"; InsertRequest insert = new InsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket()); InsertResponse insertResponse = cluster().<InsertResponse>send(insert).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, insertResponse.status()); ReferenceCountUtil.releaseLater(insertResponse.content()); assertValidMetadata(insertResponse.mutationToken()); insert = new InsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket()); insertResponse = cluster().<InsertResponse>send(insert).toBlocking().single(); assertEquals(ResponseStatus.EXISTS, insertResponse.status()); ReferenceCountUtil.releaseLater(insertResponse.content()); assertNull(insertResponse.mutationToken()); }
From source file:com.couchbase.client.core.cluster.KeyValueMessageTest.java
License:Apache License
@Test public void shouldReplaceWithoutCAS() throws Exception { final String key = "replace-key"; final String content = "replace content"; ReplaceRequest insert = new ReplaceRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket());/*from w ww . j a v a2 s . c o m*/ ReplaceResponse response = cluster().<ReplaceResponse>send(insert).toBlocking().single(); assertEquals(ResponseStatus.NOT_EXISTS, response.status()); ReferenceCountUtil.releaseLater(response.content()); assertNull(response.mutationToken()); UpsertRequest upsert = new UpsertRequest(key, Unpooled.copiedBuffer("insert content", CharsetUtil.UTF_8), bucket()); response = cluster().<UpsertResponse>send(upsert) .flatMap(new Func1<UpsertResponse, Observable<ReplaceResponse>>() { @Override public Observable<ReplaceResponse> call(UpsertResponse response) { ReferenceCountUtil.releaseLater(response.content()); return cluster().send(new ReplaceRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket())); } }).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertValidMetadata(response.mutationToken()); assertEquals(ResponseStatus.SUCCESS, response.status()); }
From source file:com.couchbase.client.core.cluster.KeyValueMessageTest.java
License:Apache License
@Test public void shouldReplaceWithFailingCAS() { final String key = "replace-key-cas-fail"; final String content = "replace content"; ReplaceRequest insert = new ReplaceRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket());//from ww w. j a va 2s. c om ReplaceResponse response = cluster().<ReplaceResponse>send(insert).toBlocking().single(); assertEquals(ResponseStatus.NOT_EXISTS, response.status()); ReferenceCountUtil.releaseLater(response.content()); assertNull(response.mutationToken()); UpsertRequest upsert = new UpsertRequest(key, Unpooled.copiedBuffer("insert content", CharsetUtil.UTF_8), bucket()); response = cluster().<UpsertResponse>send(upsert) .flatMap(new Func1<UpsertResponse, Observable<ReplaceResponse>>() { @Override public Observable<ReplaceResponse> call(UpsertResponse response) { ReferenceCountUtil.releaseLater(response.content()); return cluster().send(new ReplaceRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), 24234234L, bucket())); } }).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertEquals(ResponseStatus.EXISTS, response.status()); assertNull(response.mutationToken()); }