Fix NPEs and incorrect results in several ops within a Lettuce transaction

DATAREDIS-164
This commit is contained in:
Jennifer Hickey
2013-04-02 16:53:46 -07:00
parent 5bd03c0aa5
commit 78ad1a7cd4
4 changed files with 200 additions and 13 deletions

View File

@@ -0,0 +1,43 @@
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
/**
* Integration test of {@link LettuceConnection} transactions within a pipeline
*
* @author Jennifer Hickey
*
*/
public class LettuceConnectionPipelineTxIntegrationTests extends
LettuceConnectionTransactionIntegrationTests {
@Test(expected = RedisPipelineException.class)
public void exceptionExecuteNative() throws Exception {
connection.execute("ZadD", getClass() + "#foo\t0.90\titem");
getResults();
}
protected void initConnection() {
connection.openPipeline();
connection.multi();
}
protected List<Object> getResults() {
assertNull(connection.exec());
List<Object> results = new ArrayList<Object>();
List<Object> pipelinedResults = connection.closePipeline();
for (Object result : pipelinedResults) {
if (!"OK".equals(result) && !("QUEUED").equals(result)) {
results.add(result);
}
}
return results;
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* 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.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test of {@link LettuceConnection} functionality within a
* transaction
*
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
public class LettuceConnectionTransactionIntegrationTests extends
LettuceConnectionPipelineIntegrationTests {
@Ignore
public void testMultiDiscard() {
}
@Ignore
public void testMultiExec() {
}
@Ignore
public void testUnwatch() {
}
@Ignore
public void testWatch() {
}
/*
* Using blocking ops inside a tx does not make a lot of sense as it would
* require blocking the entire server in order to execute the block
* atomically, which in turn does not allow other clients to perform a push
* operation. Also, Lettuce always times out in these scenarios b/c it waits
* for an actual response instead of accepting the null returned by op in tx
* *
*/
@Ignore
public void testBLPop() {
}
@Ignore
public void testBRPop() {
}
@Ignore
public void testBRPopLPush() {
}
@Ignore
public void testBLPopTimeout() {
}
@Ignore
public void testBRPopTimeout() {
}
@Ignore
public void testBRPopLPushTimeout() {
}
@Test
public void testDbSize() {
connection.set("dbparam", "foo");
assertNull(connection.dbSize());
List<Object> results = getResults();
assertEquals(1, results.size());
assertTrue((Long) results.get(0) > 0);
}
@Test
public void exceptionExecuteNative() throws Exception {
actual.add(connection.execute("ZadD", getClass() + "#foo\t0.90\titem"));
// Syntax error on queued commands are swallowed and no results are
// returned
verifyResults(Arrays.asList(new Object[] {}), actual);
}
protected void initConnection() {
connection.multi();
}
protected List<Object> getResults() {
List<Object> results = new ArrayList<Object>();
List<Object> txResults = connection.exec();
for (Object result : txResults) {
if (!"OK".equals(result) && !("QUEUED").equals(result)) {
results.add(result);
}
}
return results;
}
}