@Test(expectedExceptions = IllegalArgumentException.class) public void testCouchbaseNodesAndFailoverNodeShouldThrowException() { createFor("http://localhost:8091/pools", "n1", null, _mcc); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseWithNullShouldThrowException() { createFor(null, null, null, _mcc); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseWithEmptyStringShouldThrowException() { createFor("", null, null, _mcc); }
@Test( dataProvider = "nodesAndExpectedEncodedInSessionIdDataProvider" ) public void testIsEncodeNodeIdInSessionId( final String memcachedNodes, final String failoverNodes, final boolean expectedIsEncodeNodeIdInSessionId ) { final MemcachedNodesManager result = createFor( memcachedNodes, null, null, _mcc ); assertNotNull(result); assertEquals(result.isEncodeNodeIdInSessionId(), expectedIsEncodeNodeIdInSessionId); }
@Test public void testGetCouchbaseBucketURIs() throws URISyntaxException { assertEquals(createFor("http://10.10.0.1:8091/pools", null, null, _mcc ).getCouchbaseBucketURIs(), Arrays.asList(new URI("http://10.10.0.1:8091/pools"))); assertEquals(createFor("http://10.10.0.1:8091/pools,http://10.10.0.2:8091/pools", null, null, _mcc ).getCouchbaseBucketURIs(), Arrays.asList(new URI("http://10.10.0.1:8091/pools"), new URI("http://10.10.0.2:8091/pools"))); }
@Test( dataProvider = "nodesAndExpectedCountDataProvider" ) public void testCountNodes( final String memcachedNodes, final int expectedCount ) { final MemcachedNodesManager result = createFor( memcachedNodes, null, null, _mcc ); assertNotNull(result); assertEquals(result.getCountNodes(), expectedCount); }
@Test( dataProvider = "nodesAndFailoverNodesDataProvider" ) public void testFailoverNodes(final String memcachedNodes, final String failoverNodes, final List<String> expectedFailoverNodeIds) { final MemcachedNodesManager result = createFor( memcachedNodes, failoverNodes, null, _mcc ); assertNotNull(result); assertEquals(result.getFailoverNodeIds(), expectedFailoverNodeIds); }
/** * Test for {@link MemcachedNodesManager#getNextPrimaryNodeId(String)}. * @see NodeIdList#getNextNodeId(String) * @see NodeIdListTest#testGetNextNodeId() */ @Test public void testGetNextPrimaryNodeId() { assertNull(createFor( "n1:localhost:11211", null, null, _mcc ).getNextPrimaryNodeId("n1")); assertEquals(createFor( "n1:localhost:11211,n2:localhost:11212", null, null, _mcc ).getNextPrimaryNodeId("n1"), "n2"); }
@Test( dataProvider = "nodesAndPrimaryNodesDataProvider" ) public void testPrimaryNodes(final String memcachedNodes, final String failoverNodes, final NodeIdList expectedPrimaryNodeIds) { final MemcachedNodesManager result = createFor( memcachedNodes, failoverNodes, null, _mcc ); assertNotNull(result); assertEquals(result.getPrimaryNodeIds(), expectedPrimaryNodeIds); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetNodeIdShouldThrowExceptionForNullArgument() { final MemcachedNodesManager result = createFor( "n1:localhost:11211", null, null, _mcc ); result.getNodeId(null); }
@Test( dataProvider = "testGetNodeIdDataProvider" ) public void testGetNodeId(final String memcachedNodes, final String failoverNodes, final InetSocketAddress socketAddress, final String expectedNodeId) { final MemcachedNodesManager result = createFor( memcachedNodes, failoverNodes, null, _mcc ); assertEquals(result.getNodeId(socketAddress), expectedNodeId); }
@Test( dataProvider = "testgGetAllMemcachedAddressesDataProvider" ) public void testGetAllMemcachedAddresses(final String memcachedNodes, final String failoverNodes, final Collection<InetSocketAddress> expectedSocketAddresses) { final MemcachedNodesManager result = createFor( memcachedNodes, failoverNodes, null, _mcc ); assertEquals(result.getAllMemcachedAddresses(), expectedSocketAddresses); }
@Test public void testGetSessionIdFormat() { final SessionIdFormat sessionIdFormat = createFor( "n1:localhost:11211", null, null, _mcc ).getSessionIdFormat(); assertNotNull(sessionIdFormat); }
@Test public void testGetNextAvailableNodeId() throws IOException { assertNull(createFor( "n1:localhost:11211", null, null, _mcc ).getNextAvailableNodeId("n1")); assertEquals(createFor( "n1:localhost:11211,n2:localhost:11212", null, null, _mcc ).getNextAvailableNodeId("n1"), "n2"); final StorageClientCallback mcc = mock(StorageClientCallback.class); when(mcc.get(anyString())).thenReturn(null); when(mcc.get(endsWith("n2"))).thenThrow(new OperationTimeoutException("SimulatedException")); assertNull(createFor( "n1:localhost:11211,n2:localhost:11212", null, null, mcc).getNextAvailableNodeId("n1")); assertEquals(createFor( "n1:localhost:11211,n2:localhost:11212,n3:localhost:11213", null, null, mcc).getNextAvailableNodeId("n1"), "n3"); }
@Test public void testSessionIdFormatForSingleNodeSetupShouldSupportLocking() { final SessionIdFormat sessionIdFormat = createFor( "localhost:11211", null, StorageKeyFormat.EMPTY, _mcc ).getSessionIdFormat(); assertNotNull(sessionIdFormat); final String sessionId = "12345678"; assertEquals(sessionIdFormat.createLockName(sessionId), "lock:" + sessionId); }
@Test public void testSetNodeAvailable() { final MemcachedNodesManager cut = createFor( "n1:localhost:11211,n2:localhost:11212", null, null, _mcc ); assertTrue(cut.isNodeAvailable("n1")); assertTrue(cut.isNodeAvailable("n2")); cut.setNodeAvailable("n1", false); assertFalse(cut.isNodeAvailable("n1")); assertTrue(cut.isNodeAvailable("n2")); }
protected MemcachedNodesManager createMemcachedNodesManager(final String memcachedNodes, final String failoverNodes) { final Context context = _manager.getContext(); final String webappVersion = Reflections.invoke(context, "getWebappVersion", null); final StorageKeyFormat storageKeyFormat = StorageKeyFormat.of(_storageKeyPrefix, context.getParent().getName(), context.getName(), webappVersion); return MemcachedNodesManager.createFor( memcachedNodes, failoverNodes, storageKeyFormat, _storageClientCallback); }
private MemcachedClient createMemcachedClient( final String memcachedNodes, final InetSocketAddress address ) throws IOException, InterruptedException { final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(memcachedNodes, null, null, _storageClientCallback); final ConnectionFactory cf = nodesManager.isEncodeNodeIdInSessionId() ? new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 ) : new DefaultConnectionFactory(); final MemcachedClient result = new MemcachedClient( cf, Arrays.asList( address ) ); // Wait a little bit, so that the memcached client can connect and is ready when test starts Thread.sleep( 100 ); return result; }