MemcacheClientFactoryImpl implements CacheClientFactory { @Override public CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf) throws IOException { if (connectionFactory == null) { ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); if (conf.isConsistentHashing()) { builder.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH); builder.setLocatorType(Locator.CONSISTENT); } builder.setProtocol(conf.isUseBinaryProtocol() ? Protocol.BINARY : Protocol.TEXT); if (conf.getOperationTimeout() != null) { builder.setOpTimeout(conf.getOperationTimeout()); } if (conf instanceof SpymemcachedConfiguration) { setProviderSpecificSettings(builder, (SpymemcachedConfiguration) conf); } connectionFactory = builder.build(); } return new MemcacheClientWrapper(new MemcachedClient(connectionFactory, addrs)); }  @Override CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf);  }
@Test public void createWithBaseConf() throws IOException { CacheConfiguration conf = new CacheConfiguration(); conf.setConsistentHashing(true); conf.setOperationTimeout(1000); conf.setUseBinaryProtocol(false); CacheClient client = factory.create(addrs, conf); assertNotNull(client); client.shutdown(); }
@Test public void createWithSpecificConf() throws IOException { SpymemcachedConfiguration conf = new SpymemcachedConfiguration(); conf.setConsistentHashing(true); conf.setOperationTimeout(1000); conf.setUseBinaryProtocol(false); conf.setFailureMode(FailureMode.Cancel); conf.setShouldOptimize(true); conf.setMaxReconnectDelay(1000L); conf.setTimeoutExceptionThreshold(100); conf.setUseNagleAlgorithm(false); conf.setMetricCollector(new NoopMetricCollector()); conf.setMetricType(MetricType.PERFORMANCE); CacheClient client = factory.create(addrs, conf); assertNotNull(client); client.shutdown(); }