Package org.jredis.cluster.support

Examples of org.jredis.cluster.support.HashAlgorithm


  // ------------------------------------------------------------------------
  @SuppressWarnings("static-access")
  @Test
  public void testHashByteArray() {
    Log.log("Testing HashAlgorithm hash(byte[])");
    HashAlgorithm hashAlgo = newProviderInstance();
    try {
          int c = 2000;
          int cnt = (int) (10 * Math.log(c)) * c;
          Log.log("Test hashing %d keys", cnt);
          Set<Long> hashSet = new HashSet<Long>(cnt);
          for(int i=0; i<cnt; i++){
            long hash = hashAlgo.hash(data.getRandomBytes(255));
            boolean didAdd = hashSet.add(hash);
            if(!didAdd){
              Log.log("[NOTE] got a collision (hash: %d) at idx: %d!", hash, i);
            }
          }
//          assertEquals(hashSet.size(), cnt);
          if(hashSet.size() == cnt)
            Log.log("Hashed %d keys with no collisions", cnt);
          else
            Log.log("Hashed %d keys with %d collisions", cnt, cnt - hashSet.size());
         
          // edge case - NULL input not allowed
          boolean didRaiseError = false;
          try {
        byte[] nullref = null;
            hashAlgo.hash(nullref);
          }
          catch (IllegalArgumentException e){ didRaiseError = true; }
          catch (RuntimeException what) { fail("Unexpected runtime exception raised",what); }
          assertTrue(didRaiseError, "Expecting a raised exception for null input");
         
          // edge case - zero length input not allowed
          didRaiseError = false;
          try {
        byte[] zerobytes = data.getRandomBytes(0);
        hashAlgo.hash(zerobytes);
          }
          catch (IllegalArgumentException e){ didRaiseError = true; }
          catch (RuntimeException what) { fail("Unexpected runtime exception raised",what); }
          assertTrue(didRaiseError, "Expecting a raised exception for zero length input");
        }
View Full Code Here


   
  /* (non-Javadoc) @see org.jredis.cluster.model.StaticHashCluster.Support#newHashAlgorithm() */
    @Override
    protected HashAlgorithm newHashAlgorithm () {
      // TDOO: get this from the clusterspec
      return new HashAlgorithm() {
      public long hash (byte[] kb) {
              return kb.hashCode();
            }
      };
    }
View Full Code Here

TOP

Related Classes of org.jredis.cluster.support.HashAlgorithm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.