Permalink
Browse files

Added compliance check for JRedis and JRedisFuture -- TESTED

 - generated report added to redis_version_compliance.txt
 - to gen, just run CheckRedisCompliance.java
  • Loading branch information...
alphazero committed Feb 4, 2012
1 parent 6691d1b commit 9dd1c3d479e2b28092ef57bf43a53c696e9907bd
@@ -0,0 +1,119 @@
+auth
+ping
+echo
+set
+setnx
+setex
+get
+del
+exists
+setbit
+getbit
+setrange
+getrange
+incr
+decr
+incrby
+decrby
+select
+randomkey
+keys
+dbsize
+lastsave
+save
+bgsave
+bgrewriteaof
+shutdown
+move
+rename
+renamenx
+lpush
+rpush
+lpushx
+rpushx
+linsert
+lpop
+rpop
+llen
+lindex
+lrange
+ltrim
+type
+lset
+sadd
+srem
+smove
+sismember
+scard
+spop
+srandmember
+sinter
+sinterstore
+sunion
+sunionstore
+sdiff
+sdiffstore
+sync
+flushdb
+flushall
+sort
+lrem
+rpoplpush
+info
+mget
+monitor
+expire
+expireat
+getset
+ttl
+persist
+slaveof
+debug
+mset
+msetnx
+zadd
+zincrby
+zrange
+zrangebyscore
+zrevrangebyscore
+zcount
+zrevrange
+zcard
+zrem
+zscore
+zremrangebyscore
+multi
+exec
+discard
+blpop
+brpop
+brpoplpush
+append
+strlen
+zrank
+zrevrank
+hset
+hsetnx
+hget
+hmset
+hmget
+hdel
+hlen
+zremrangebyrank
+zunionstore
+zinterstore
+hkeys
+hvals
+hgetall
+hexists
+config
+hincrby
+subscribe
+unsubscribe
+psubscribe
+punsubscribe
+publish
+watch
+unwatch
+object
+client
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2009-2012 Joubin Houshyar
+ *
+ * This file is part of JRedis.
+ *
+ * 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.jredis.compliance;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jredis.JRedis;
+import org.jredis.JRedisFuture;
+
+/**
+ * Informal. A munge of redis.h is used to produce the canonical
+ * Redis commands for a given Redis release. This program reflects
+ * over JRedis to determine missing commands.
+ * <p>
+ * TODOS:
+ * <li>need to address minor variations introduced for Java readablility.</li>
+ * <li>beef up annotations to tighten up the compliance check</li>
+ * <li>apt cycle on release would be best</li>
+ *
+ *
+ * @author Joubin Houshyar <alphazero@sensesay.net>
+ * @date: Feb 1, 2012
+ */
+public class CheckRedisCompliance {
+ // TODO: drive this via annotation on the JRedis interface
+ static final String spec_file_path = "META-INF";
+ static final String spec_file_prefix = "redis-commands";
+ static final String spec_file_ext = "txt";
+ final int major;
+ final int minor;
+ final InputStream specfilein;
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+ /**
+ * @throws Exception
+ */
+ public CheckRedisCompliance(int major, int minor) throws Exception {
+ this.major = major;
+ this.minor = minor;
+ specfilein = getSpecFileInputStream(major, minor);
+ }
+ private final void run() throws Exception {
+ List<String> cmdlist = getSpecCommandList();
+ checkAndReportCompliance(cmdlist, JRedis.class);
+ checkAndReportCompliance(cmdlist, JRedisFuture.class);
+ }
+ private List<String> checkAndReportCompliance(List<String> cmdlist, Class<?> jredis_class) {
+ Method[] pubmethods = jredis_class.getMethods();
+ Set<String> uniqueMethodNames = new HashSet<String>();
+ for(Method m : pubmethods)
+ uniqueMethodNames.add(m.getName());
+
+ List<String> notsupported = new ArrayList<String>();
+ for(String cmd : cmdlist) {
+ if(!uniqueMethodNames.contains(cmd))
+ notsupported.add(cmd);
+ }
+ if(!notsupported.isEmpty()) {
+ reportNonCompliance(notsupported, jredis_class.getSimpleName());
+ }
+
+ return notsupported;
+ }
+ private void reportNonCompliance(List<String> notsupported, String simpleName) {
+ System.out.format("\n /// non-compliance report for %-12s //////////////\n", simpleName);
+ int i = 0;
+ for(String cmd : notsupported){
+ System.out.format("[%2d] %s\n",i++, cmd);
+ }
+ System.out.format("\n /////////////////////////////////////////////////////////\n", simpleName);
+ }
+ private List<String> getSpecCommandList() throws IOException {
+ List<String> cmdlist = new ArrayList<String>();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(specfilein));
+ String cmd = null;
+ while((cmd=reader.readLine()) != null){
+ cmdlist.add(cmd);
+ }
+ return cmdlist;
+ }
+ private static final InputStream getSpecFileInputStream(int major, int minor) {
+ String fname =
+ String.format("%s%s%s-%d.%d.n.%s",
+ spec_file_path, File.separator,spec_file_prefix, major, minor, spec_file_ext)
+ .toString();
+ InputStream in = JRedis.class.getClassLoader().getResourceAsStream(fname);
+ if(in == null){
+ String errmsg = String.format("No spec file found: <%s>", fname).toString();
+ throw new IllegalArgumentException(errmsg);
+ }
+ return in;
+ }
+ public static void main(String[] args) {
+ try {
+ new CheckRedisCompliance(2, 4).run();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
@@ -1,2 +1,86 @@
compliance: Redis 2.4.0
tested with: Redis 2.4.6
+
+-- compliance report (see api/src/test/org/jredis/compliance package --
+
+/// non-compliance report for JRedis //////////////
+[ 0] auth
+[ 1] setex
+[ 2] setbit
+[ 3] getbit
+[ 4] setrange
+[ 5] getrange
+[ 6] select
+[ 7] shutdown
+[ 8] lpushx
+[ 9] rpushx
+[10] linsert
+[11] sync
+[12] monitor
+[13] persist
+[14] zrevrangebyscore
+[15] exec
+[16] blpop
+[17] brpop
+[18] brpoplpush
+[19] strlen
+[20] hsetnx
+[21] hmset
+[22] hmget
+[23] zunionstore
+[24] zinterstore
+[25] config
+[26] hincrby
+[27] subscribe
+[28] unsubscribe
+[29] psubscribe
+[30] punsubscribe
+[31] publish
+[32] watch
+[33] unwatch
+[34] object
+[35] client
+
+/////////////////////////////////////////////////////////
+
+/// non-compliance report for JRedisFuture //////////////
+[ 0] auth
+[ 1] setex
+[ 2] setbit
+[ 3] getbit
+[ 4] setrange
+[ 5] getrange
+[ 6] select
+[ 7] shutdown
+[ 8] lpushx
+[ 9] rpushx
+[10] linsert
+[11] sync
+[12] monitor
+[13] persist
+[14] zrevrangebyscore
+[15] multi
+[16] exec
+[17] discard
+[18] blpop
+[19] brpop
+[20] brpoplpush
+[21] strlen
+[22] hsetnx
+[23] hmset
+[24] hmget
+[25] zunionstore
+[26] zinterstore
+[27] config
+[28] hincrby
+[29] subscribe
+[30] unsubscribe
+[31] psubscribe
+[32] punsubscribe
+[33] publish
+[34] watch
+[35] unwatch
+[36] object
+[37] client
+
+/////////////////////////////////////////////////////////

0 comments on commit 9dd1c3d

Please sign in to comment.