Skip to content

Commit

Permalink
Fixes issue #62
Browse files Browse the repository at this point in the history
  • Loading branch information
lordofthejars committed Apr 10, 2013
1 parent 031613b commit b8adc2c
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 239 deletions.
Expand Up @@ -18,6 +18,7 @@
import com.lordofthejars.nosqlunit.neo4j.InMemoryNeo4j;
import com.lordofthejars.nosqlunit.neo4j.Neo4jRule;

@UsingDataSet(locations="matrix.xml", loadStrategy=LoadStrategyEnum.CLEAN_INSERT)
public class WhenNeoIsRequired {

@ClassRule
Expand All @@ -31,13 +32,17 @@ public class WhenNeoIsRequired {


@Test
@UsingDataSet(locations="matrix.xml", loadStrategy=LoadStrategyEnum.CLEAN_INSERT)
public void neo_node_should_be_returned() {
MatrixManager matrixManager = new MatrixManager(graphDatabaseService);
Node neo = matrixManager.getNeoNode();
assertThat((String)neo.getProperty("name"), is("Thomas Anderson"));
}


@Test
public void neo_node_should_be_returnedd() {
MatrixManager matrixManager = new MatrixManager(graphDatabaseService);
Node neo = matrixManager.getNeoNode();
assertThat((String)neo.getProperty("name"), is("Thomas Anderson"));
}

}
Expand Up @@ -4,8 +4,10 @@
import static org.hamcrest.CoreMatchers.is;

import static com.lordofthejars.nosqlunit.redis.ManagedRedisConfigurationBuilder.newManagedRedisConfiguration;
import static com.lordofthejars.nosqlunit.redis.ManagedRedisLifecycleManagerBuilder.newManagedRedis;
import static com.lordofthejars.nosqlunit.redis.ManagedRedis.ManagedRedisRuleBuilder.newManagedRedisRule;
import static com.lordofthejars.nosqlunit.redis.RedisRule.RedisRuleBuilder.newRedisRule;
import static com.lordofthejars.nosqlunit.redis.replication.ReplicationGroupBuilder.master;

import java.io.File;
import java.util.concurrent.TimeUnit;
Expand All @@ -24,42 +26,44 @@
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum;
import com.lordofthejars.nosqlunit.redis.ManagedRedis;
import com.lordofthejars.nosqlunit.redis.RedisRule;
import com.lordofthejars.nosqlunit.redis.replication.ReplicationManagedRedis;

public class WhenMasterSlaveReplicationIsConfigured {

static {
System.setProperty("REDIS_HOME", "/opt/redis-2.4.17");
}

private static final File MASTER_CONFIGURATION_DIRECTORY = new File(
"src/test/resources/com/lordofthejars/nosqlunit/demo/redis/master-redis.conf");
private static final File SLAVE_CONFIGURATION_DIRECTORY = new File(
"src/test/resources/com/lordofthejars/nosqlunit/demo/redis/slave-redis.conf");
private static final String MASTER_CONFIGURATION_DIRECTORY =
"src/test/resources/com/lordofthejars/nosqlunit/demo/redis/master-redis.conf";
private static final String SLAVE_CONFIGURATION_DIRECTORY =
"src/test/resources/com/lordofthejars/nosqlunit/demo/redis/slave-redis.conf";

@ClassRule
public static ManagedRedis masterRedis = newManagedRedisRule()
.configurationPath(MASTER_CONFIGURATION_DIRECTORY.getAbsolutePath()).targetPath("target/redis1").port(6379).build();

@ClassRule
public static ManagedRedis slaveRedis = newManagedRedisRule()
.configurationPath(SLAVE_CONFIGURATION_DIRECTORY.getAbsolutePath()).targetPath("target/redis2").port(6380).build();
public static ReplicationManagedRedis replication = master(
newManagedRedis()
.redisPath("/opt/redis-2.6.12")
.targetPath("target/redism")
.configurationPath(getConfigurationFilePath(MASTER_CONFIGURATION_DIRECTORY))
.port(6379)
.build()
)
.slave(
newManagedRedis()
.redisPath("/opt/redis-2.6.12")
.targetPath("target/rediss1")
.configurationPath(getConfigurationFilePath(SLAVE_CONFIGURATION_DIRECTORY))
.port(6380)
.slaveOf("127.0.0.1", 6379)
.build())
.get();


@Rule
public RedisRule masterRedisRule = newRedisRule().configure(
newManagedRedisConfiguration().connectionIdentifier("master").port(6379).build()).build();

@Rule
public RedisRule slaveRedisRule = newRedisRule().configure(
newManagedRedisConfiguration().connectionIdentifier("slave").port(6380).slaveOf("127.0.0.1", 6379).build())
.build();

@Inject
@Named("master")
private Jedis masterConnection;

@Inject
@Named("slave")
private Jedis slaveConnection;

@Test
@UsingDataSet(withSelectiveLocations = { @Selective(identifier = "master", locations = "book.json") }, loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
Expand All @@ -70,9 +74,16 @@ public void should_replicate_data_into_slave_node() throws InterruptedException

TimeUnit.SECONDS.sleep(5);

Jedis slaveConnection = new Jedis("localhost", 6380);

theHobbitTitle = slaveConnection.hget("The Hobbit", "title");
assertThat(theHobbitTitle, is("The Hobbit"));

}

private static String getConfigurationFilePath(String fileName) {
File configurationFile = new File(fileName);
return configurationFile.getAbsolutePath();
}

}
Expand Up @@ -373,89 +373,14 @@ slowlog-log-slower-than 10000
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128

################################ VIRTUAL MEMORY ###############################

### WARNING! Virtual Memory is deprecated in Redis 2.4
### The use of Virtual Memory is strongly discouraged.

# Virtual Memory allows Redis to work with datasets bigger than the actual
# amount of RAM needed to hold the whole dataset in memory.
# In order to do so very used keys are taken in memory while the other keys
# are swapped into a swap file, similarly to what operating systems do
# with memory pages.
#
# To enable VM just set 'vm-enabled' to yes, and set the following three
# VM parameters accordingly to your needs.

vm-enabled no
# vm-enabled yes

# This is the path of the Redis swap file. As you can guess, swap files
# can't be shared by different Redis instances, so make sure to use a swap
# file for every redis process you are running. Redis will complain if the
# swap file is already in use.
#
# The best kind of storage for the Redis swap file (that's accessed at random)
# is a Solid State Disk (SSD).
#
# *** WARNING *** if you are using a shared hosting the default of putting
# the swap file under /tmp is not secure. Create a dir with access granted
# only to Redis user and configure Redis to create the swap file there.
vm-swap-file /tmp/redis.swap

# vm-max-memory configures the VM to use at max the specified amount of
# RAM. Everything that deos not fit will be swapped on disk *if* possible, that
# is, if there is still enough contiguous space in the swap file.
#
# With vm-max-memory 0 the system will swap everything it can. Not a good
# default, just specify the max amount of RAM you can in bytes, but it's
# better to leave some margin. For instance specify an amount of RAM
# that's more or less between 60 and 80% of your free RAM.
vm-max-memory 0

# Redis swap files is split into pages. An object can be saved using multiple
# contiguous pages, but pages can't be shared between different objects.
# So if your page is too big, small objects swapped out on disk will waste
# a lot of space. If you page is too small, there is less space in the swap
# file (assuming you configured the same number of total swap file pages).
#
# If you use a lot of small objects, use a page size of 64 or 32 bytes.
# If you use a lot of big objects, use a bigger page size.
# If unsure, use the default :)
vm-page-size 32

# Number of total memory pages in the swap file.
# Given that the page table (a bitmap of free/used pages) is taken in memory,
# every 8 pages on disk will consume 1 byte of RAM.
#
# The total swap size is vm-page-size * vm-pages
#
# With the default of 32-bytes memory pages and 134217728 pages Redis will
# use a 4 GB swap file, that will use 16 MB of RAM for the page table.
#
# It's better to use the smallest acceptable value for your application,
# but the default is large in order to work in most conditions.
vm-pages 134217728

# Max number of VM I/O threads running at the same time.
# This threads are used to read/write data from/to swap file, since they
# also encode and decode objects from disk to memory or the reverse, a bigger
# number of threads can help with big objects even if they can't help with
# I/O itself as the physical device may not be able to couple with many
# reads/writes operations at the same time.
#
# The special value of 0 turn off threaded I/O and enables the blocking
# Virtual Memory implementation.
vm-max-threads 4

############################### ADVANCED CONFIG ###############################

# Hashes are encoded in a special way (much more memory efficient) when they
# have at max a given numer of elements, and the biggest element does not
# exceed a given threshold. You can configure this limits with the following
# configuration directives.
hash-max-zipmap-entries 512
hash-max-zipmap-value 64

# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
Expand Down
Expand Up @@ -373,89 +373,14 @@ slowlog-log-slower-than 10000
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128

################################ VIRTUAL MEMORY ###############################

### WARNING! Virtual Memory is deprecated in Redis 2.4
### The use of Virtual Memory is strongly discouraged.

# Virtual Memory allows Redis to work with datasets bigger than the actual
# amount of RAM needed to hold the whole dataset in memory.
# In order to do so very used keys are taken in memory while the other keys
# are swapped into a swap file, similarly to what operating systems do
# with memory pages.
#
# To enable VM just set 'vm-enabled' to yes, and set the following three
# VM parameters accordingly to your needs.

vm-enabled no
# vm-enabled yes

# This is the path of the Redis swap file. As you can guess, swap files
# can't be shared by different Redis instances, so make sure to use a swap
# file for every redis process you are running. Redis will complain if the
# swap file is already in use.
#
# The best kind of storage for the Redis swap file (that's accessed at random)
# is a Solid State Disk (SSD).
#
# *** WARNING *** if you are using a shared hosting the default of putting
# the swap file under /tmp is not secure. Create a dir with access granted
# only to Redis user and configure Redis to create the swap file there.
vm-swap-file /tmp/redis.swap

# vm-max-memory configures the VM to use at max the specified amount of
# RAM. Everything that deos not fit will be swapped on disk *if* possible, that
# is, if there is still enough contiguous space in the swap file.
#
# With vm-max-memory 0 the system will swap everything it can. Not a good
# default, just specify the max amount of RAM you can in bytes, but it's
# better to leave some margin. For instance specify an amount of RAM
# that's more or less between 60 and 80% of your free RAM.
vm-max-memory 0

# Redis swap files is split into pages. An object can be saved using multiple
# contiguous pages, but pages can't be shared between different objects.
# So if your page is too big, small objects swapped out on disk will waste
# a lot of space. If you page is too small, there is less space in the swap
# file (assuming you configured the same number of total swap file pages).
#
# If you use a lot of small objects, use a page size of 64 or 32 bytes.
# If you use a lot of big objects, use a bigger page size.
# If unsure, use the default :)
vm-page-size 32

# Number of total memory pages in the swap file.
# Given that the page table (a bitmap of free/used pages) is taken in memory,
# every 8 pages on disk will consume 1 byte of RAM.
#
# The total swap size is vm-page-size * vm-pages
#
# With the default of 32-bytes memory pages and 134217728 pages Redis will
# use a 4 GB swap file, that will use 16 MB of RAM for the page table.
#
# It's better to use the smallest acceptable value for your application,
# but the default is large in order to work in most conditions.
vm-pages 134217728

# Max number of VM I/O threads running at the same time.
# This threads are used to read/write data from/to swap file, since they
# also encode and decode objects from disk to memory or the reverse, a bigger
# number of threads can help with big objects even if they can't help with
# I/O itself as the physical device may not be able to couple with many
# reads/writes operations at the same time.
#
# The special value of 0 turn off threaded I/O and enables the blocking
# Virtual Memory implementation.
vm-max-threads 4

############################### ADVANCED CONFIG ###############################

# Hashes are encoded in a special way (much more memory efficient) when they
# have at max a given numer of elements, and the biggest element does not
# exceed a given threshold. You can configure this limits with the following
# configuration directives.
hash-max-zipmap-entries 512
hash-max-zipmap-value 64

# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
Expand Down
Expand Up @@ -36,11 +36,6 @@ public ManagedRedisConfigurationBuilder password(String password) {
return this;
}

public ManagedRedisConfigurationBuilder slaveOf(String masterHost, int masterPort) {
this.redisConfiguration.salveOf(masterHost, masterPort);
return this;
}

public RedisConfiguration build() {

Jedis jedis = new Jedis(this.redisConfiguration.getHost(), this.redisConfiguration.getPort());
Expand All @@ -53,11 +48,6 @@ public RedisConfiguration build() {
}

}

if(this.redisConfiguration.isSlave()) {
jedis.slaveof(this.redisConfiguration.getMasterHost(), this.redisConfiguration.getMasterPort());
}

this.redisConfiguration.setDatabaseOperation(new RedisOperation(jedis));
return redisConfiguration;
}
Expand Down
Expand Up @@ -155,8 +155,8 @@ private List<String> buildOperationSystemProgramAndArguments() {
List<String> programAndArguments = new ArrayList<String>();

programAndArguments.add(getExecutablePath());
addSlaveOfParameter(programAndArguments);
addConfigurationPath(programAndArguments);
addSlaveOfParameter(programAndArguments);

for (String argument : this.singleCommandArguments) {
programAndArguments.add(argument);
Expand Down Expand Up @@ -191,9 +191,7 @@ private String redisExecutable() {
private List<String> addSlaveOfParameter(List<String> programAndArguments) {

if(isMasterDefined()) {
programAndArguments.add(SLAVE_OF_ARGUMENT);
programAndArguments.add(this.masterHost);
programAndArguments.add(Integer.toString(this.masterPort));
programAndArguments.add(SLAVE_OF_ARGUMENT+" "+this.masterHost+" "+Integer.toString(this.masterPort));
}

return programAndArguments;
Expand Down

0 comments on commit b8adc2c

Please sign in to comment.