Skip to content

Commit

Permalink
Introduce RedisLoadingException to represent Redis LOADING response #682
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jan 23, 2018
1 parent c893778 commit d4f8c5d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/main/java/com/lambdaworks/redis/ExceptionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* Factory for Redis exceptions.
*
*
* @author Mark Paluch
* @since 4.5
*/
Expand All @@ -30,7 +30,7 @@ private ExceptionFactory() {

/**
* Create a {@link RedisCommandTimeoutException} with a detail message given the timeout.
*
*
* @param timeout the timeout value.
* @param unit the {@link TimeUnit}.
* @return the {@link RedisCommandTimeoutException}.
Expand All @@ -41,7 +41,7 @@ public static RedisCommandTimeoutException createTimeoutException(long timeout,

/**
* Create a {@link RedisCommandTimeoutException} with a detail message given the message and timeout.
*
*
* @param message the detail message.
* @param timeout the timeout value.
* @param unit the {@link TimeUnit}.
Expand All @@ -54,7 +54,7 @@ public static RedisCommandTimeoutException createTimeoutException(String message
/**
* Create a {@link RedisCommandExecutionException} with a detail message. Specific Redis error messages may create subtypes
* of {@link RedisCommandExecutionException}.
*
*
* @param message the detail message.
* @return the {@link RedisCommandExecutionException}.
*/
Expand All @@ -65,7 +65,7 @@ public static RedisCommandExecutionException createExecutionException(String mes
/**
* Create a {@link RedisCommandExecutionException} with a detail message and optionally a {@link Throwable cause}. Specific
* Redis error messages may create subtypes of {@link RedisCommandExecutionException}.
*
*
* @param message the detail message.
* @param cause the nested exception, may be {@literal null}.
* @return the {@link RedisCommandExecutionException}.
Expand All @@ -82,6 +82,10 @@ public static RedisCommandExecutionException createExecutionException(String mes
return cause != null ? new RedisNoScriptException(message, cause) : new RedisNoScriptException(message);
}

if (message.startsWith("LOADING")) {
return cause != null ? new RedisLoadingException(message, cause) : new RedisLoadingException(message);
}

return cause != null ? new RedisCommandExecutionException(message, cause) : new RedisCommandExecutionException(
message);
}
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/lambdaworks/redis/RedisLoadingException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2018 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 com.lambdaworks.redis;

/**
* Exception that gets thrown when Redis is loading a dataset into memory and replying with a {@code LOADING} error response.
*
* @author Mark Paluch
* @since 4.5
*/
@SuppressWarnings("serial")
public class RedisLoadingException extends RedisCommandExecutionException {

/**
* Create a {@code RedisLoadingException} with the specified detail message.
*
* @param msg the detail message.
*/
public RedisLoadingException(String msg) {
super(msg);
}

/**
* Create a {@code RedisLoadingException} with the specified detail message and nested exception.
*
* @param msg the detail message.
* @param cause the nested exception.
*/
public RedisLoadingException(String msg, Throwable cause) {
super(msg, cause);
}
}
14 changes: 12 additions & 2 deletions src/test/java/com/lambdaworks/redis/ExceptionFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
Expand Down Expand Up @@ -55,4 +55,14 @@ public void shouldCreateExecutionException() {
assertThat(ExceptionFactory.createExecutionException(null, new IllegalStateException())).isInstanceOf(
RedisCommandExecutionException.class).hasRootCauseInstanceOf(IllegalStateException.class);
}
}

@Test
public void shouldCreateLoadingException() {

assertThat(ExceptionFactory.createExecutionException("LOADING foo bar")).isInstanceOf(RedisLoadingException.class)
.hasMessage("LOADING foo bar").hasNoCause();
assertThat(ExceptionFactory.createExecutionException("LOADING foo bar", new IllegalStateException()))
.isInstanceOf(RedisLoadingException.class).hasMessage("LOADING foo bar")
.hasRootCauseInstanceOf(IllegalStateException.class);
}
}

0 comments on commit d4f8c5d

Please sign in to comment.