Browse files

Add pausible store for testing store failures via JMX. It is just a w…

…rapper around an in-memory store that exposes a JMX pause and unpause function.
  • Loading branch information...
1 parent f9bb61d commit 18819d7fafff151589b58e976275e7cb90ea94af @jkreps jkreps committed Jun 21, 2009
View
31 test/integration/voldemort/store/pausable/PausableStorageConfiguration.java
@@ -0,0 +1,31 @@
+package voldemort.store.pausable;
+
+import voldemort.server.VoldemortConfig;
+import voldemort.store.StorageConfiguration;
+import voldemort.store.StorageEngine;
+import voldemort.store.memory.InMemoryStorageEngine;
+import voldemort.utils.ByteArray;
+
+/**
+ * The storage configuration for the PausableStorageEngine
+ *
+ * @author jay
+ *
+ */
+public class PausableStorageConfiguration implements StorageConfiguration {
+
+ private final String TYPE_NAME = "pausable";
+
+ public PausableStorageConfiguration(@SuppressWarnings("unused") VoldemortConfig config) {}
+
+ public void close() {}
+
+ public StorageEngine<ByteArray, byte[]> getStore(String name) {
+ return new PausableStorageEngine<ByteArray, byte[]>(new InMemoryStorageEngine<ByteArray, byte[]>(name));
+ }
+
+ public String getType() {
+ return TYPE_NAME;
+ }
+
+}
View
105 test/integration/voldemort/store/pausable/PausableStorageEngine.java
@@ -0,0 +1,105 @@
+package voldemort.store.pausable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.log4j.Logger;
+
+import voldemort.VoldemortException;
+import voldemort.annotations.jmx.JmxOperation;
+import voldemort.store.StorageEngine;
+import voldemort.store.StoreCapabilityType;
+import voldemort.store.memory.InMemoryStorageEngine;
+import voldemort.utils.ClosableIterator;
+import voldemort.utils.Pair;
+import voldemort.versioning.Version;
+import voldemort.versioning.Versioned;
+
+/**
+ * A storage engine that can be paused via JMX to simulate a failure for testing
+ *
+ * @author jay
+ *
+ * @param <K> The type of the key
+ * @param <V> The type of the value
+ */
+public class PausableStorageEngine<K, V> implements StorageEngine<K, V> {
+
+ private static final Logger logger = Logger.getLogger(PausableStorageEngine.class);
+
+ private final InMemoryStorageEngine<K, V> inner;
+ private final ReadWriteLock lock;
+
+ public PausableStorageEngine(InMemoryStorageEngine<K, V> inner) {
+ super();
+ this.inner = inner;
+ this.lock = new ReentrantReadWriteLock();
+ }
+
+ public void close() throws VoldemortException {
+ inner.close();
+ }
+
+ public boolean delete(K key, Version version) {
+ try {
+ lock.readLock().lock();
+ return inner.delete(key);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ public List<Versioned<V>> get(K key) {
+ try {
+ lock.readLock().lock();
+ return inner.get(key);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ public Map<K, List<Versioned<V>>> getAll(Iterable<K> keys) {
+ try {
+ lock.readLock().lock();
+ return inner.getAll(keys);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ public void put(K key, Versioned<V> value) {
+ try {
+ lock.readLock().lock();
+ inner.put(key, value);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ public ClosableIterator<Pair<K, Versioned<V>>> entries() {
+ return inner.entries();
+ }
+
+ public Object getCapability(StoreCapabilityType capability) {
+ return inner.getCapability(capability);
+ }
+
+ public String getName() {
+ return inner.getName();
+ }
+
+ @JmxOperation(description = "Pause all operations on the storage engine.")
+ public void pause() {
+ logger.info("Pausing store '" + getName() + "'.");
+ this.lock.writeLock().lock();
+ }
+
+ @JmxOperation(description = "Unpause the storage engine.")
+ public void unpause() {
+ logger.info("Unpausing store '" + getName() + "'.");
+ this.lock.writeLock().unlock();
+ }
+
+}

0 comments on commit 18819d7

Please sign in to comment.