-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from lucaspouzac/memcached-java-client_compati…
…bility Add compatibility with Gwhalin Memcached Java Client
- Loading branch information
Showing
7 changed files
with
223 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/net/rubyeye/xmemcached/networking/ClosedMemcachedSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.rubyeye.xmemcached.networking; | ||
|
||
import com.google.code.yanf4j.core.Session; | ||
|
||
import net.rubyeye.xmemcached.utils.InetSocketAddressWrapper; | ||
|
||
public interface ClosedMemcachedSession extends Session { | ||
|
||
public void setAllowReconnect(boolean allow); | ||
|
||
public boolean isAllowReconnect(); | ||
|
||
public InetSocketAddressWrapper getInetSocketAddressWrapper(); | ||
|
||
@Deprecated | ||
public int getWeight(); | ||
|
||
@Deprecated | ||
public int getOrder(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/net/rubyeye/xmemcached/test/unittest/MockMemcachedSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package net.rubyeye.xmemcached.test.unittest; | ||
|
||
import net.rubyeye.xmemcached.buffer.BufferAllocator; | ||
import net.rubyeye.xmemcached.networking.MemcachedSession; | ||
import net.rubyeye.xmemcached.utils.InetSocketAddressWrapper; | ||
|
||
public class MockMemcachedSession extends MockSession implements MemcachedSession { | ||
|
||
|
||
public MockMemcachedSession(int port) { | ||
super(port); | ||
} | ||
|
||
|
||
public void setAllowReconnect(boolean allow) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public boolean isAllowReconnect() { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
public void setBufferAllocator(BufferAllocator allocator) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public InetSocketAddressWrapper getInetSocketAddressWrapper() { | ||
InetSocketAddressWrapper inetSocketAddressWrapper = new InetSocketAddressWrapper(getRemoteSocketAddress(), 1, 1, null); | ||
inetSocketAddressWrapper.setRemoteAddressStr("localhost/127.0.0.1:" + this.port); | ||
return inetSocketAddressWrapper; | ||
} | ||
|
||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public int getWeight() { | ||
// TODO Auto-generated method stub | ||
return 1; | ||
} | ||
|
||
public int getOrder() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
public void quit() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public boolean isAuthFailed() { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
public void setAuthFailed(boolean authFailed) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...d/test/unittest/impl/KetamaMemcachedSessionLocatorGwhalinMemcachedJavaClientUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package net.rubyeye.xmemcached.test.unittest.impl; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.rubyeye.xmemcached.HashAlgorithm; | ||
import net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator; | ||
import net.rubyeye.xmemcached.test.unittest.MockMemcachedSession; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.google.code.yanf4j.core.Session; | ||
|
||
public class KetamaMemcachedSessionLocatorGwhalinMemcachedJavaClientUnitTest extends | ||
AbstractMemcachedSessionLocatorUnitTest { | ||
|
||
@Before | ||
public void setUp() { | ||
this.locator = new KetamaMemcachedSessionLocator(HashAlgorithm.KETAMA_HASH, false, true); | ||
} | ||
|
||
@Test | ||
public void testGetSessionByKey_MoreSessions() { | ||
MockMemcachedSession session1 = new MockMemcachedSession(8080); | ||
MockMemcachedSession session2 = new MockMemcachedSession(8081); | ||
MockMemcachedSession session3 = new MockMemcachedSession(8082); | ||
System.err.print(session1.getInetSocketAddressWrapper().getRemoteAddressStr()); | ||
|
||
List<Session> list = new ArrayList<Session>(); | ||
list.add(session1); | ||
list.add(session2); | ||
list.add(session3); | ||
this.locator.updateSessions(list); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session1, this.locator.getSessionByKey("a3")); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session1, this.locator.getSessionByKey("a3")); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session1, this.locator.getSessionByKey("a3")); | ||
|
||
} | ||
|
||
@Test | ||
public void testGetSessionByKey_MoreSessions_OneClosed() { | ||
MockMemcachedSession session1 = new MockMemcachedSession(8080); | ||
MockMemcachedSession session2 = new MockMemcachedSession(8081); | ||
session1.close(); | ||
MockMemcachedSession session3 = new MockMemcachedSession(8082); | ||
List<Session> list = new ArrayList<Session>(); | ||
list.add(session1); | ||
list.add(session2); | ||
list.add(session3); | ||
this.locator.updateSessions(list); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session2, this.locator.getSessionByKey("a3")); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session2, this.locator.getSessionByKey("a3")); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session2, this.locator.getSessionByKey("a3")); | ||
|
||
} | ||
|
||
@Test | ||
public void testGetSessionByKey_MoreSessions_OneClosed_FailureMode() { | ||
this.locator.setFailureMode(true); | ||
MockMemcachedSession session1 = new MockMemcachedSession(8080); | ||
MockMemcachedSession session2 = new MockMemcachedSession(8081); | ||
session1.close(); | ||
MockMemcachedSession session3 = new MockMemcachedSession(8082); | ||
List<Session> list = new ArrayList<Session>(); | ||
list.add(session1); | ||
list.add(session2); | ||
list.add(session3); | ||
this.locator.updateSessions(list); | ||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session1, this.locator.getSessionByKey("a3")); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session1, this.locator.getSessionByKey("a3")); | ||
|
||
assertSame(session2, this.locator.getSessionByKey("a1")); | ||
assertSame(session3, this.locator.getSessionByKey("a2")); | ||
assertSame(session1, this.locator.getSessionByKey("a3")); | ||
} | ||
|
||
} |