Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added ChunkedPipelineConnection test. TESTED.

  • Loading branch information...
commit f05b29c6a19e07a75e59f9b7e7d1bc6587ac130a 1 parent a96ec72
@alphazero authored
View
28 core/ri/src/main/java/org/jredis/ri/alphazero/connection/ChunkedPipelineConnection.java
@@ -247,8 +247,16 @@ protected final InputStream newInputStream (InputStream socketInputStream) throw
}
if(sendreq){
- System.arraycopy(reqbytes, 0, chunkbuff, off, reqbyteslen);
- off+=reqbyteslen;
+ // good enough hack for reqs > MTU
+ // assumes that overflow was true!
+ if(reqbyteslen > MTU_SIZE) {
+ out.write(reqbytes);
+ out.flush();
+ }
+ else {
+ System.arraycopy(reqbytes, 0, chunkbuff, off, reqbyteslen);
+ off+=reqbyteslen;
+ }
}
if(doflush) {
@@ -305,26 +313,32 @@ void onResponseHandlerError (ClientRuntimeException cre, PendingRequest request)
// Inner Class
// ------------------------------------------------------------------------
- public final class PendingCPRequest extends PendingRequest {
+ final class PendingCPRequest extends PendingRequest {
final ChunkedPipelineConnection pipeline;
public PendingCPRequest(ChunkedPipelineConnection pipeline, Command cmd) {
super(cmd);
this.pipeline = pipeline;
}
- @Override
+ @Override final
public Response get()
throws InterruptedException, ExecutionException {
- pipeline.queueRequest(Command.FLUSH);
+ requestFlush();
return super.get();
}
- @Override
+ @Override final
public Response get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException
{
- pipeline.queueRequest(Command.FLUSH);
+ requestFlush();
return super.get(timeout, unit);
}
+ final
+ private void requestFlush() {
+ if(cmd != Command.QUIT) {
+ pipeline.queueRequest(Command.FLUSH);
+ }
+ }
}
/**
* Provides the response processing logic as a {@link Runnable}.
View
87 core/ri/src/test/java/org/jredis/ri/alphazero/JRedisChunkedPIpelineClientTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2009-2012 Joubin Houshyar
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jredis.ri.alphazero;
+
+import static org.testng.Assert.fail;
+import org.jredis.ClientRuntimeException;
+import org.jredis.JRedisFuture;
+import org.jredis.connector.ConnectionSpec;
+import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
+import org.jredis.ri.alphazero.support.Log;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.Test;
+
+/**
+ * [TODO: document me!]
+ *
+ * @author Joubin Houshyar (alphazero@sensesay.net)
+ * @version alpha.0, Jan 18, 2012
+ *
+ */
+//@Test(invocationCount=20, threadPoolSize=5, sequential=false)
+@Test(sequential = true, suiteName="JRedisChunkedPipeline-tests")
+public class JRedisChunkedPIpelineClientTest extends JRedisFutureProviderTestsBase {
+
+ // ------------------------------------------------------------------------
+ // TEST SETUP
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.jredis.ri.ProviderTestBase#newProviderInstance()
+ */
+ @Override
+ protected JRedisFuture newProviderInstance () {
+ JRedisFuture provider = null;
+ try {
+ ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(this.host, this.port, this.db2, this.password.getBytes());
+ provider = new JRedisChunkedPipeline(connectionSpec);
+ }
+ catch (ClientRuntimeException e) {
+ Log.error(e.getLocalizedMessage());
+ }
+ return provider;
+ }
+ // ------------------------------------------------------------------------
+ // The Tests
+ // ========================================================= JRedisClient
+ /**
+ * We define and run any additional, provider specific tests here. The
+ * basic generally applicable JRedis interface method test are defined
+ * in the super class.
+ *
+ * Here we test Quit in a post test method to insure all tests have been
+ * completed.
+ */
+ // ------------------------------------------------------------------------
+
+ /**
+ * Pipeline quit.
+ * We first ping and await the response to insure pipeline has processed
+ * all pending responses, and then issue the quit command.
+ */
+ @AfterTest
+ public void testQuit() {
+ try {
+ JRedisFuture pipeline = getProviderInstance();
+ pipeline.ping().get();
+ pipeline.quit().get();
+ }
+ catch (Exception e) {
+ fail("QUIT" + e);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.