@Override protected void initClient(ConnectionFactory cf) throws Exception { if (TestConfig.getInstance().getClientMode() == ClientMode.Dynamic) { List<InetSocketAddress> addrs = AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11212"); MemcachedClient staticClient = new MemcachedClient(addrs); if (TestConfig.getInstance().getEngineType().isSetConfigSupported()) { staticClient.setConfig( addrs.get(0), ConfigurationType.CLUSTER, "1\n" + "localhost.localdomain|" + TestConfig.IPV4_ADDR + "|" + "11212"); client = new MemcachedClient(cf, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11212")); staticClient.setConfig( addrs.get(0), ConfigurationType.CLUSTER, "2\nlocalhost.localdomain|" + TestConfig.IPV4_ADDR + "|64213"); } else { staticClient.set( ConfigurationType.CLUSTER.getValueWithNameSpace(), 0, "1\n" + "localhost.localdomain|" + TestConfig.IPV4_ADDR + "|" + "11212"); client = new MemcachedClient(cf, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11212")); staticClient.set( ConfigurationType.CLUSTER.getValueWithNameSpace(), 0, "2\nlocalhost.localdomain|" + TestConfig.IPV4_ADDR + "|64213"); } // Add a delay to allow time for dynamic mode client to pickup the config. Thread.sleep(10000); } else { client = new MemcachedClient(cf, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":64213")); } }
@Test public void testDelayedFlush() throws Exception { String current_config = null; Collection<NodeEndPoint> endpoints = new ArrayList<NodeEndPoint>(); if (TestConfig.getInstance().getClientMode().equals(ClientMode.Dynamic) && !TestConfig.getInstance().getEngineType().isSetConfigSupported()) { current_config = getCurrentConfigAndClusterEndpoints(client, endpoints); } assertNull(client.get("test1")); assert client.set("test1", 5, "test1value").getStatus().isSuccess(); assert client.set("test2", 5, "test2value").getStatus().isSuccess(); assertEquals("test1value", client.get("test1")); assertEquals("test2value", client.get("test2")); assert client.flush(2).getStatus().isSuccess(); Thread.sleep(2100); if (TestConfig.getInstance().getClientMode().equals(ClientMode.Dynamic) && !TestConfig.getInstance().getEngineType().isSetConfigSupported()) { Thread.sleep(1000); restoreClusterConfig(current_config, endpoints); Thread.sleep(1000); // Wait for the config to restore } assertNull(client.get("test1")); assertNull(client.get("test2")); assert !client.asyncGet("test1").getStatus().isSuccess(); assert !client.asyncGet("test2").getStatus().isSuccess(); }
@Test public void testConfigCmds() { // This is for basic testing for the config APIs. DR mode specific tests are implemented // separately. if (TestConfig.getInstance().getClientMode() == ClientMode.Dynamic) { return; } final String config = "1\nlocalhost|127.0.0.1|11211"; client.getVersions(); Collection<NodeEndPoint> endpoints = client.getAvailableNodeEndPoints(); InetSocketAddress sa = endpoints.iterator().next().getInetSocketAddress(); if (TestConfig.getInstance().getEngineType().isSetConfigSupported()) { client.deleteConfig(sa, ConfigurationType.CLUSTER); assertNull(client.getConfig(sa, ConfigurationType.CLUSTER)); client.setConfig(sa, ConfigurationType.CLUSTER, config); String configFromServer = (String) client.getConfig(sa, ConfigurationType.CLUSTER); assertEquals(config, configFromServer); client.deleteConfig(sa, ConfigurationType.CLUSTER); assertNull(client.getConfig(sa, ConfigurationType.CLUSTER)); } else { String configKey = ConfigurationType.CLUSTER.getValueWithNameSpace(); client.delete(configKey); assertNull(client.get(configKey)); client.set(configKey, 0, config); String configFromServer = (String) client.get(configKey); assertEquals(config, configFromServer); client.delete(configKey); assertNull(client.get(configKey)); } }
@Test public void testDelayedflushCancellation() throws Exception { String current_config = null; Collection<NodeEndPoint> endpoints = new ArrayList<NodeEndPoint>(); if (TestConfig.getInstance().getClientMode().equals(ClientMode.Dynamic) && !TestConfig.getInstance().getEngineType().isSetConfigSupported()) { current_config = getCurrentConfigAndClusterEndpoints(client, endpoints); } tryTestSequence(client.flush(3)); if (TestConfig.getInstance().getClientMode().equals(ClientMode.Dynamic) && !TestConfig.getInstance().getEngineType().isSetConfigSupported()) { restoreClusterConfig(current_config, endpoints); } }
@Test public void testBroadcastAfterShutdown() throws Exception { String current_config = null; Collection<NodeEndPoint> endpoints = new ArrayList<NodeEndPoint>(); if (TestConfig.getInstance().getClientMode().equals(ClientMode.Dynamic) && !TestConfig.getInstance().getEngineType().isSetConfigSupported()) { current_config = getCurrentConfigAndClusterEndpoints(client, endpoints); } client.shutdown(); try { Future<?> f = client.flush(); fail("Expected IllegalStateException, got " + f.get()); } catch (IllegalStateException e) { // OK } finally { if (TestConfig.getInstance().getClientMode().equals(ClientMode.Dynamic) && !TestConfig.getInstance().getEngineType().isSetConfigSupported()) { Thread.sleep(1000); restoreClusterConfig(current_config, endpoints); Thread.sleep(1000); // Wait for the config to restore } initClient(); // init for tearDown } }
/** * Returns the {@link AsyncEventQueueDescription} with the given configuration name from {@link * AsyncEventQueuePrms#names}. */ public static AsyncEventQueueDescription getAsyncEventQueueDescription( String asyncEventQueueConfig) { if (asyncEventQueueConfig == null) { throw new IllegalArgumentException("asyncEventQueueConfig cannot be null"); } log.info("Looking up async event queue config: " + asyncEventQueueConfig); AsyncEventQueueDescription aeqd = TestConfig.getInstance().getAsyncEventQueueDescription(asyncEventQueueConfig); if (aeqd == null) { String s = asyncEventQueueConfig + " not found in " + BasePrms.nameForKey(AsyncEventQueuePrms.names); throw new HydraRuntimeException(s); } log.info("Looked up async event queue config:\n" + aeqd); return aeqd; }