Created
July 29, 2019 11:35
-
-
Save diegolovison/3c2f981bfca970393cf6233046a59a50 to your computer and use it in GitHub Desktop.
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
Index: client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java (revision 653c77fd0d3be2ccb21137be12ceea2147206e14) | |
+++ client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java (revision c62f4b8c6d99ee8a78c7f26b37dc4226c89705c3) | |
@@ -292,7 +292,7 @@ | |
private void actualStart() { | |
log.debugf("Starting remote cache manager %x", System.identityHashCode(this)); | |
- channelFactory = new ChannelFactory(); | |
+ channelFactory = createChannelFactory(); | |
if (marshaller == null) { | |
marshaller = configuration.marshaller(); | |
@@ -344,6 +344,10 @@ | |
started = true; | |
} | |
+ public ChannelFactory createChannelFactory() { | |
+ return new ChannelFactory(); | |
+ } | |
+ | |
@Override | |
public boolean isTransactional(String cacheName) { | |
ClientStatistics stats = ClientStatistics.dummyClientStatistics(timeService); | |
Index: client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/ChannelFactory.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/ChannelFactory.java (revision 653c77fd0d3be2ccb21137be12ceea2147206e14) | |
+++ client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/ChannelFactory.java (revision c62f4b8c6d99ee8a78c7f26b37dc4226c89705c3) | |
@@ -336,7 +336,7 @@ | |
} | |
@GuardedBy("lock") | |
- private Collection<SocketAddress> updateTopologyInfo(byte[] cacheName, Collection<SocketAddress> newServers, boolean quiet) { | |
+ protected Collection<SocketAddress> updateTopologyInfo(byte[] cacheName, Collection<SocketAddress> newServers, boolean quiet) { | |
Collection<SocketAddress> servers = topologyInfo.getServers(new WrappedByteArray(cacheName)); | |
Set<SocketAddress> addedServers = new HashSet<>(newServers); | |
addedServers.removeAll(servers); | |
Index: server/runtime/src/test/java/org/infinispan/server/test/ContainerInfinispanServerDriver.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- server/runtime/src/test/java/org/infinispan/server/test/ContainerInfinispanServerDriver.java (revision 653c77fd0d3be2ccb21137be12ceea2147206e14) | |
+++ server/runtime/src/test/java/org/infinispan/server/test/ContainerInfinispanServerDriver.java (revision c62f4b8c6d99ee8a78c7f26b37dc4226c89705c3) | |
@@ -3,9 +3,11 @@ | |
import java.io.File; | |
import java.net.InetAddress; | |
import java.net.InetSocketAddress; | |
+import java.net.SocketAddress; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.ArrayList; | |
+import java.util.Collection; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
@@ -15,6 +17,9 @@ | |
import javax.management.remote.JMXServiceURL; | |
import org.infinispan.Version; | |
+import org.infinispan.client.hotrod.RemoteCacheManager; | |
+import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; | |
+import org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory; | |
import org.infinispan.test.Exceptions; | |
import org.infinispan.util.logging.LogFactory; | |
import org.testcontainers.DockerClientFactory; | |
@@ -87,13 +92,6 @@ | |
"-Dcom.sun.management.jmxremote.authenticate=false", | |
"-Dcom.sun.management.jmxremote.ssl=false" | |
) | |
- .expose( | |
- 11222, // Protocol endpoint | |
- 11221, // Memcached endpoint | |
- 7800, // JGroups TCP | |
- 43366, // JGroups MPING | |
- 9999 // JMX Remoting | |
- ) | |
.build()); | |
CountdownLatchLoggingConsumer latch; | |
if (configuration.numServers() > 1) { | |
@@ -103,6 +101,7 @@ | |
} | |
for (int i = 0; i < configuration.numServers(); i++) { | |
GenericContainer container = new GenericContainer(image); | |
+ container.withExposedPorts(11222); | |
// Create directories which we will bind the container to | |
createServerHierarchy(rootDir, Integer.toString(i), | |
@@ -132,11 +131,16 @@ | |
@Override | |
public InetSocketAddress getServerAddress(int server, int port) { | |
GenericContainer container = containers.get(server); | |
+ //return new InetSocketAddress(getIpAddressFromContainer(container), port); | |
+ return new InetSocketAddress("localhost", container.getMappedPort(port)); | |
+ } | |
+ | |
+ private String getIpAddressFromContainer(GenericContainer container) { | |
InspectContainerResponse containerInfo = container.getContainerInfo(); | |
ContainerNetwork network = containerInfo.getNetworkSettings().getNetworks().values().iterator().next(); | |
// We talk directly to the container, and not through forwarded addresses on localhost because of | |
// https://github.com/testcontainers/testcontainers-java/issues/452 | |
- return new InetSocketAddress(network.getIpAddress(), port); | |
+ return network.getIpAddress(); | |
} | |
@Override | |
@@ -168,4 +172,34 @@ | |
return jmxConnector.getMBeanServerConnection(); | |
}); | |
} | |
+ | |
+ @Override | |
+ public RemoteCacheManager createRemoteCacheManager(ConfigurationBuilder builder) { | |
+ return new RemoteCacheManager(builder.build()) { | |
+ @Override | |
+ public ChannelFactory createChannelFactory() { | |
+ return new ChannelFactory() { | |
+ protected Collection<SocketAddress> updateTopologyInfo(byte[] cacheName, Collection<SocketAddress> newServers, boolean quiet) { | |
+ List<SocketAddress> localHostServers = new ArrayList<>(); | |
+ for (SocketAddress address : newServers) { | |
+ InetSocketAddress inetSocketAddress = (InetSocketAddress) address; | |
+ GenericContainer container = getGeneriContainerBy(inetSocketAddress); | |
+ localHostServers.add(new InetSocketAddress("localhost", container.getMappedPort(inetSocketAddress.getPort()))); | |
+ } | |
+ return super.updateTopologyInfo(cacheName, localHostServers, quiet); | |
+ } | |
+ }; | |
+ } | |
+ }; | |
+ } | |
+ | |
+ private GenericContainer getGeneriContainerBy(InetSocketAddress inetSocketAddress) { | |
+ for (GenericContainer container : containers) { | |
+ String hostName = getIpAddressFromContainer(container); | |
+ if (inetSocketAddress.getHostName().equals(hostName)) { | |
+ return container; | |
+ } | |
+ } | |
+ throw new IllegalStateException(); | |
+ } | |
} | |
Index: server/runtime/src/test/java/org/infinispan/server/test/EmbeddedInfinispanServerDriver.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- server/runtime/src/test/java/org/infinispan/server/test/EmbeddedInfinispanServerDriver.java (revision 653c77fd0d3be2ccb21137be12ceea2147206e14) | |
+++ server/runtime/src/test/java/org/infinispan/server/test/EmbeddedInfinispanServerDriver.java (revision c62f4b8c6d99ee8a78c7f26b37dc4226c89705c3) | |
@@ -11,6 +11,8 @@ | |
import javax.management.MBeanServerConnection; | |
+import org.infinispan.client.hotrod.RemoteCacheManager; | |
+import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; | |
import org.infinispan.manager.CacheContainer; | |
import org.infinispan.manager.DefaultCacheManager; | |
import org.infinispan.server.DefaultExitHandler; | |
@@ -98,4 +100,9 @@ | |
DefaultCacheManager cacheManager = servers.get(server).getCacheManagers().values().iterator().next(); | |
return cacheManager.getCacheManagerConfiguration().globalJmxStatistics().mbeanServerLookup().getMBeanServer(); | |
} | |
+ | |
+ @Override | |
+ public RemoteCacheManager createRemoteCacheManager(ConfigurationBuilder builder) { | |
+ return new RemoteCacheManager(builder.build()); | |
+ } | |
} | |
Index: server/runtime/src/test/java/org/infinispan/server/test/InfinispanServerDriver.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- server/runtime/src/test/java/org/infinispan/server/test/InfinispanServerDriver.java (revision 653c77fd0d3be2ccb21137be12ceea2147206e14) | |
+++ server/runtime/src/test/java/org/infinispan/server/test/InfinispanServerDriver.java (revision c62f4b8c6d99ee8a78c7f26b37dc4226c89705c3) | |
@@ -29,6 +29,8 @@ | |
import javax.management.MBeanServerConnection; | |
import javax.security.auth.x500.X500Principal; | |
+import org.infinispan.client.hotrod.RemoteCacheManager; | |
+import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; | |
import org.infinispan.commons.util.Util; | |
import org.infinispan.lifecycle.ComponentStatus; | |
import org.infinispan.security.AuthorizationPermission; | |
@@ -292,4 +294,6 @@ | |
* @param server the index of the server | |
*/ | |
public abstract MBeanServerConnection getJmxConnection(int server); | |
+ | |
+ public abstract RemoteCacheManager createRemoteCacheManager(ConfigurationBuilder builder); | |
} | |
Index: server/runtime/src/test/java/org/infinispan/server/test/InfinispanServerRule.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- server/runtime/src/test/java/org/infinispan/server/test/InfinispanServerRule.java (revision 653c77fd0d3be2ccb21137be12ceea2147206e14) | |
+++ server/runtime/src/test/java/org/infinispan/server/test/InfinispanServerRule.java (revision c62f4b8c6d99ee8a78c7f26b37dc4226c89705c3) | |
@@ -100,9 +100,9 @@ | |
// Add all known server addresses | |
for (int i = 0; i < serverDriver.configuration.numServers(); i++) { | |
InetSocketAddress serverAddress = serverDriver.getServerAddress(i, 11222); | |
- builder.addServer().host(serverAddress.getHostName()).port(serverAddress.getPort()); | |
+ builder.addServer().host("localhost").port(serverAddress.getPort()); | |
} | |
- RemoteCacheManager remoteCacheManager = new RemoteCacheManager(builder.build()); | |
+ RemoteCacheManager remoteCacheManager = serverDriver.createRemoteCacheManager(builder); | |
return remoteCacheManager; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment