|
1 | 1 | package redis.clients.jedis;
|
2 | 2 |
|
| 3 | +import static org.hamcrest.Matchers.containsString; |
3 | 4 | import static org.junit.Assert.*;
|
| 5 | +import static org.junit.Assert.assertTrue; |
4 | 6 | import static redis.clients.jedis.Protocol.Command.INCR;
|
5 | 7 | import static redis.clients.jedis.Protocol.Command.GET;
|
6 | 8 | import static redis.clients.jedis.Protocol.Command.SET;
|
|
9 | 11 | import java.util.ArrayList;
|
10 | 12 | import java.util.List;
|
11 | 13 | import java.util.Set;
|
| 14 | + |
| 15 | +import org.hamcrest.MatcherAssert; |
12 | 16 | import org.junit.After;
|
13 | 17 | import org.junit.Before;
|
14 | 18 | import org.junit.Test;
|
@@ -213,6 +217,23 @@ public void transactionResponseWithError() {
|
213 | 217 | assertEquals("bar", r.get());
|
214 | 218 | }
|
215 | 219 |
|
| 220 | + @Test |
| 221 | + public void transactionPropagatesErrorsBeforeExec() { |
| 222 | + // A command may fail to be queued, so there may be an error before EXEC is called. |
| 223 | + // For instance the command may be syntactically wrong (wrong number of arguments, wrong command name, ...) |
| 224 | + CommandObject<String> invalidCommand = |
| 225 | + new CommandObject<>(new CommandObjects().commandArguments(SET), BuilderFactory.STRING); |
| 226 | + |
| 227 | + Transaction t = new Transaction(conn); |
| 228 | + t.appendCommand(invalidCommand); |
| 229 | + t.set("foo","bar"); |
| 230 | + JedisDataException exception = assertThrows(JedisDataException.class, t::exec); |
| 231 | + Throwable[] suppressed = exception.getSuppressed(); |
| 232 | + assertNotNull("Suppressed exceptions should not be null", suppressed); |
| 233 | + assertTrue("There should be at least one suppressed exception", suppressed.length > 0); |
| 234 | + MatcherAssert.assertThat(suppressed[0].getMessage(), containsString("ERR wrong number of arguments")); |
| 235 | + } |
| 236 | + |
216 | 237 | @Test
|
217 | 238 | public void testCloseable() {
|
218 | 239 | Transaction transaction = new Transaction(conn);
|
|
0 commit comments