/** * This runs through some simple tests of the MemcacheClient. * * <p>Command line args: args[0] = number of threads to spawn args[1] = number of runs per thread * args[2] = size of object to store * * @param args the command line arguments */ public static void main(String[] args) { if (!UnitTests.class.desiredAssertionStatus()) { System.err.println("WARNING: assertions are disabled!"); try { Thread.sleep(3000); } catch (InterruptedException e) { } } String[] serverlist = { "192.168.1.50:1620", "192.168.1.50:1621", "192.168.1.50:1622", "192.168.1.50:1623", "192.168.1.50:1624", "192.168.1.50:1625", "192.168.1.50:1626", "192.168.1.50:1627", "192.168.1.50:1628", "192.168.1.50:1629" }; Integer[] weights = {1, 1, 1, 1, 10, 5, 1, 1, 1, 3}; if (args.length > 0) serverlist = args; // initialize the pool for memcache servers SockIOPool pool = SockIOPool.getInstance("test"); pool.setServers(serverlist); pool.setWeights(weights); pool.setMaxConn(250); pool.setNagle(false); pool.setHashingAlg(SockIOPool.CONSISTENT_HASH); pool.initialize(); mc = new MemcachedClient("test"); runAlTests(mc); }
public static void main(String[] args) { // memcached should be running on port 11211 but NOT on 11212 // FIXME // BasicConfigurator.configure(); String[] servers = {"192.168.1.1:1624", "192.168.1.1:1625"}; SockIOPool pool = SockIOPool.getInstance(); pool.setServers(servers); pool.setFailover(true); pool.setInitConn(10); pool.setMinConn(5); pool.setMaxConn(250); pool.setMaintSleep(30); pool.setNagle(false); pool.setSocketTO(3000); pool.setAliveCheck(true); pool.initialize(); MemCachedClient memCachedClient = new MemCachedClient(); // turn off most memcached client logging: // FIXME // com.danga.jmemcached.Logger.getLogger( MemCachedClient.class.getName() ).setLevel( // com.danga.jmemcached.Logger.LEVEL_WARN ); for (int i = 0; i < 10; i++) { boolean success = memCachedClient.set("" + i, "Hello!"); String result = (String) memCachedClient.get("" + i); System.out.println(String.format("set( %d ): %s", i, success)); System.out.println(String.format("get( %d ): %s", i, result)); } System.out.println("\n\t -- sleeping --\n"); try { Thread.sleep(10000); } catch (Exception ex) { } for (int i = 0; i < 10; i++) { boolean success = memCachedClient.set("" + i, "Hello!"); String result = (String) memCachedClient.get("" + i); System.out.println(String.format("set( %d ): %s", i, success)); System.out.println(String.format("get( %d ): %s", i, result)); } }