Skip to content

Commit

Permalink
Polishing #671
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Dec 18, 2017
1 parent de953ef commit f81db76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/lambdaworks/redis/ReadFrom.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Defines from which Redis nodes data is read.
*
* @author Mark Paluch
* @author Ryosuke Hasebe
* @since 4.0
*/
public abstract class ReadFrom {
Expand Down Expand Up @@ -70,6 +71,7 @@ public abstract class ReadFrom {
* @throws IllegalArgumentException if {@code name} is empty, {@literal null} or the {@link ReadFrom} preset is unknown.
*/
public static ReadFrom valueOf(String name) {

if (LettuceStrings.isEmpty(name)) {
throw new IllegalArgumentException("Name must not be empty");
}
Expand Down Expand Up @@ -110,5 +112,4 @@ public interface Nodes extends Iterable<RedisNodeDescription> {
*/
List<RedisNodeDescription> getNodes();
}

}
27 changes: 14 additions & 13 deletions src/test/java/com/lambdaworks/redis/cluster/ReadFromTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

/**
* @author Mark Paluch
* @author Ryosuke Hasebe
*/
public class ReadFromTest {

Expand All @@ -40,7 +41,7 @@ public class ReadFromTest {
private RedisClusterNode slave = new RedisClusterNode();

@Before
public void before() throws Exception {
public void before() {

master.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.MASTER));
nearest.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.SLAVE));
Expand All @@ -52,67 +53,67 @@ public void before() throws Exception {
}

@Test
public void master() throws Exception {
public void master() {
List<RedisNodeDescription> result = ReadFrom.MASTER.select(getNodes());
assertThat(result).hasSize(1).containsOnly(master);
}

@Test
public void masterPreferred() throws Exception {
public void masterPreferred() {
List<RedisNodeDescription> result = ReadFrom.MASTER_PREFERRED.select(getNodes());
assertThat(result).hasSize(3).containsExactly(master, nearest, slave);
}

@Test
public void slave() throws Exception {
public void slave() {
List<RedisNodeDescription> result = ReadFrom.SLAVE.select(getNodes());
assertThat(result).hasSize(2).contains(nearest, slave);
}

@Test
public void slavePreferred() throws Exception {
public void slavePreferred() {
List<RedisNodeDescription> result = ReadFrom.SLAVE_PREFERRED.select(getNodes());
assertThat(result).hasSize(3).containsExactly(nearest, slave, master);
}

@Test
public void nearest() throws Exception {
public void nearest() {
List<RedisNodeDescription> result = ReadFrom.NEAREST.select(getNodes());
assertThat(result).hasSize(3).containsExactly(nearest, master, slave);
}

@Test(expected = IllegalArgumentException.class)
public void valueOfNull() throws Exception {
public void valueOfNull() {
ReadFrom.valueOf(null);
}

@Test(expected = IllegalArgumentException.class)
public void valueOfUnknown() throws Exception {
public void valueOfUnknown() {
ReadFrom.valueOf("unknown");
}

@Test
public void valueOfNearest() throws Exception {
public void valueOfNearest() {
assertThat(ReadFrom.valueOf("nearest")).isEqualTo(ReadFrom.NEAREST);
}

@Test
public void valueOfMaster() throws Exception {
public void valueOfMaster() {
assertThat(ReadFrom.valueOf("master")).isEqualTo(ReadFrom.MASTER);
}

@Test
public void valueOfMasterPreferred() throws Exception {
public void valueOfMasterPreferred() {
assertThat(ReadFrom.valueOf("masterPreferred")).isEqualTo(ReadFrom.MASTER_PREFERRED);
}

@Test
public void valueOfSlave() throws Exception {
public void valueOfSlave() {
assertThat(ReadFrom.valueOf("slave")).isEqualTo(ReadFrom.SLAVE);
}

@Test
public void valueOfSlavePreferred() throws Exception {
public void valueOfSlavePreferred() {
assertThat(ReadFrom.valueOf("slavePreferred")).isEqualTo(ReadFrom.SLAVE_PREFERRED);
}

Expand Down

0 comments on commit f81db76

Please sign in to comment.