Permalink
Browse files

Add some test classes used to test bucket

  • Loading branch information...
1 parent f65853b commit d96912426b70816e6b716cf7c66436497f297e08 @trondn committed Apr 12, 2011
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2011 Couchbase, Inc.
+ *
+ * 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 org.membase.jmemcachedtest.tests;
+
+import java.io.IOException;
+import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.membase.jmemcachedtest.MemcachedClient;
+
+/**
+ * This is a small dummy client that just drives load to a bucket.
+ *
+ * @author Trond Norbye
+ */
+public class LoadClient implements Runnable {
+
+ private final String host;
+ private final int port;
+ private final String auth;
+ private final String password;
+ private static final int MEMCACHED_OPS_SLEEPTIME = 250;
+ private static final int MEMCACHED_RECONNECT_SLEEPTIME = 1000;
+
+ public LoadClient(String host, int port, String auth, String password) {
+ this.host = host;
+ this.port = port;
+ this.auth = auth;
+ this.password = password;
+ }
+
+ private void sleep(int amount) {
+ try {
+ Thread.sleep(amount);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(LoadClient.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public void run() {
+ Random rand = new Random();
+ while (true) {
+ MemcachedClient client = new MemcachedClient(host, port, auth, password);
+
+ try {
+ while (true) {
+ if (rand.nextInt(30) < 20) {
+ client.get(rand.nextInt(1000));
+ } else {
+ int a = rand.nextInt(1000) + 2;
+ client.bulkLoad(a / 2, a, 120, 150);
+ }
+ rand.nextInt(MEMCACHED_OPS_SLEEPTIME);
+ }
+ } catch (IOException ex) {
+ sleep(MEMCACHED_RECONNECT_SLEEPTIME);
+ }
+ }
+ }
+}
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011 Couchbase, Inc.
+ *
+ * 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 org.membase.jmemcachedtest.tests;
+
+/**
+ * "kill" membase by driving a hard bucket creation/deletion/list load while
+ * we're running traffic to the cluster as well :)
+ *
+ * @author Trond Norbye
+ */
+public class MembaseKiller {
+
+ public static final int MAX_BUCKETS = 10;
+ public static final int NUM_BUCKET_THREADS = 3;
+
+ public static final String RestServer = "localhost:8091";
+ public static final String Moxi = "localhost";
+ public static final int MoxiPort = 11211;
+
+
+ public static void main(String[] args) {
+ for (int ii = 0; ii < NUM_BUCKET_THREADS; ++ii) {
+ Thread t = new Thread(new RestBucketWorker(RestServer, "/opt/membase/bin/cli/membase", MAX_BUCKETS));
+ t.start();
+ }
+
+ for (int ii = 0; ii < MAX_BUCKETS; ++ii) {
+ for (int jj = 0; jj < 5; ++jj) {
+ Thread t = new Thread(new LoadClient(Moxi, MoxiPort, "" + ii, RestBucketWorker.BUCKET_PASSWORD));
+ t.start();
+ }
+ }
+ }
+
+ private MembaseKiller() {
+ }
+}
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2011 Couchbase, Inc.
+ *
+ * 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 org.membase.jmemcachedtest.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.membase.jmemcachedtest.MemcachedClient;
+
+/**
+ * This is a test program used to hammer a standalone memcached with bucket
+ * engine. To run this program you should export the environment variable:
+ * BUCKET_ENGINE_DIABLE_AUTH_PHASE before you start memcached and bucket engine.
+ *
+ * This test program connects to localhost on port 11211 and will nuke
+ * the directories from the engine between each time it creates the bucket
+ * to avoid reading the database the next time we generate the same bucket.
+ *
+ * @author Trond Norbye <trond.norbye@gmail.com>
+ */
+public class RandomBucketWorker implements Runnable {
+
+ MemcachedClient client;
+ // @todo fix for windows
+ private static final String MODULE = "/opt/membase/bin/ep_engine/ep.so";
+ private final String config;
+ private final String bucketname;
+ private final File dbdir;
+
+ public RandomBucketWorker(String hostname, int port, String bucketname, File dataroot) {
+ client = new MemcachedClient(hostname, port);
+ StringBuilder sb = new StringBuilder();
+ sb.append("vb0=false;");
+ sb.append("waitforwarmup=false;");
+ sb.append("ht_size=3079;");
+ sb.append("ht_locks=5;");
+ sb.append("failpartialwarmup=false;");
+ sb.append("db_shards=4;");
+ sb.append("shardpattern=%d/%b-%i.mb;");
+ sb.append("db_strategy=multiMTVBDB;");
+ sb.append("tap_noop_interval=20;");
+ sb.append("max_txn_size=1000;");
+ sb.append("max_size=104857600;");
+ sb.append("tap_keepalive=300;");
+
+ if (!dataroot.exists()) {
+ dataroot.mkdirs();
+ }
+ dbdir = new File(dataroot, bucketname);
+ purgeDbDir();
+ File dbname = new File(dbdir, "db");
+ sb.append("dbname=");
+ sb.append(dbname.getAbsolutePath());
+ sb.append(";");
+ config = sb.toString();
+ this.bucketname = bucketname;
+ }
+
+ @Override
+ public void run() {
+ try {
+ while (true) {
+ if (client.createBucket(bucketname, MODULE, config)) {
+ if (!client.selectBucket(bucketname)) {
+ throw new IOException("Failed to select bucket");
+ }
+ for (int ii = 0; ii < 1024; ++ii) {
+ client.setVbucket(ii);
+ }
+ client.bulkLoad(10, 100, 120, 150);
+ if (client.deleteBucket(bucketname, true)) {
+ purgeDbDir();
+ }
+ } else {
+ System.out.println("Failed");
+
+ }
+ }
+ } catch (IOException ex) {
+ Logger.getLogger(RandomBucketWorker.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ private void rmdir(File dir) {
+ for (File f : dir.listFiles()) {
+ if (f.isDirectory()) {
+ if (f.getName().startsWith(".")) {
+ rmdir(f);
+ }
+ } else {
+ f.delete();
+ }
+ }
+ dir.delete();
+ }
+
+ private void purgeDbDir() {
+ if (dbdir.exists()) {
+ rmdir(dbdir);
+ }
+ dbdir.mkdir();
+ }
+
+ public static void main(String argv[]) {
+ for (int ii = 0; ii < 10; ++ii) {
+ Thread t = new Thread(new RandomBucketWorker("localhost", 11211, "foo-" + ii, new File("/tmp/bucket-tester")));
+ t.start();
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit d969124

Please sign in to comment.