forked from dustin/java-memcached-client
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve hostname of node again during reconnection
This is essential when memcached cluster is built on cloud infra, e.g. k8s, where nodes move and their ips vary.
- Loading branch information
Showing
6 changed files
with
89 additions
and
2 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
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
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
54 changes: 54 additions & 0 deletions
54
src/test/java/net/spy/memcached/protocol/binary/AddressResolutionTest.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,54 @@ | ||
package net.spy.memcached.protocol.binary; | ||
|
||
import junit.framework.Assert; | ||
import net.spy.memcached.DefaultConnectionFactory; | ||
import net.spy.memcached.MemcachedNode; | ||
import net.spy.memcached.ops.Operation; | ||
import org.junit.Test; | ||
|
||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.SocketAddress; | ||
import java.nio.channels.SocketChannel; | ||
import java.util.concurrent.ArrayBlockingQueue; | ||
import java.util.concurrent.BlockingQueue; | ||
|
||
public class AddressResolutionTest { | ||
@Test | ||
public void testResolveAddressWithHostname() throws Exception { | ||
BlockingQueue<Operation> queue = new ArrayBlockingQueue<>(1); | ||
MemcachedNode node = new BinaryMemcachedNodeImpl(new InetSocketAddress("memcached.org", 80), | ||
SocketChannel.open(), 1024, queue, queue, queue, 1024L, false, | ||
1024, 1024, new DefaultConnectionFactory()); | ||
SocketAddress originalSocketAddress = node.getSocketAddress(); | ||
SocketAddress resolvedSocketAddress = node.getSocketAddress(true); | ||
Assert.assertEquals("socket address with hostname couldn't be resolved", | ||
originalSocketAddress, resolvedSocketAddress); | ||
} | ||
|
||
@Test | ||
public void testResolveAddressWithAddress() throws Exception { | ||
BlockingQueue<Operation> queue = new ArrayBlockingQueue<>(1); | ||
MemcachedNode node = new BinaryMemcachedNodeImpl( | ||
new InetSocketAddress(InetAddress.getByName("memcached.org"), 80), | ||
SocketChannel.open(), 1024, queue, queue, queue, 1024L, false, | ||
1024, 1024, new DefaultConnectionFactory()); | ||
SocketAddress originalSocketAddress = node.getSocketAddress(); | ||
SocketAddress resolvedSocketAddress = node.getSocketAddress(true); | ||
Assert.assertEquals("socket address with address couldn't be resolved", | ||
originalSocketAddress, resolvedSocketAddress); | ||
} | ||
|
||
@Test | ||
public void testResolveAddressWithAddressAsHostname() throws Exception { | ||
BlockingQueue<Operation> queue = new ArrayBlockingQueue<>(1); | ||
MemcachedNode node = new BinaryMemcachedNodeImpl( | ||
new InetSocketAddress(InetAddress.getByName("memcached.org").getHostAddress(), 80), | ||
SocketChannel.open(), 1024, queue, queue, queue, 1024L, false, | ||
1024, 1024, new DefaultConnectionFactory()); | ||
SocketAddress originalSocketAddress = node.getSocketAddress(); | ||
SocketAddress resolvedSocketAddress = node.getSocketAddress(true); | ||
Assert.assertEquals("socket address with address as hostname couldn't be resolved", | ||
originalSocketAddress, resolvedSocketAddress); | ||
} | ||
} |