This is an automated email from the ASF dual-hosted git repository.
mck pushed a commit to branch cassandra-2.2
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-2.2 by this push:
new a8ef9c9 Fix unit tests to listen on FBUtilities.getLocalAddress()
instead of InetAddress.getLocalHost()
a8ef9c9 is described below
commit a8ef9c9ad1495f3eb9dc1ef09c0995926561fd8c
Author: Mick Semb Wever <[email protected]>
AuthorDate: Wed Mar 4 23:05:11 2020 +0100
Fix unit tests to listen on FBUtilities.getLocalAddress() instead of
InetAddress.getLocalHost()
patch by Mick Semb Wever; reviewed by Benjamin Lerer for CASSANDRA-15622
---
src/java/org/apache/cassandra/utils/GuidGenerator.java | 6 ++----
.../cql3/validation/operations/ThriftCQLTester.java | 10 +++-------
test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java | 14 +++-----------
.../unit/org/apache/cassandra/security/SSLFactoryTest.java | 4 ++--
test/unit/org/apache/cassandra/triggers/TriggersTest.java | 14 +++++++-------
5 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/src/java/org/apache/cassandra/utils/GuidGenerator.java
b/src/java/org/apache/cassandra/utils/GuidGenerator.java
index 33f7330..09c7f3e 100644
--- a/src/java/org/apache/cassandra/utils/GuidGenerator.java
+++ b/src/java/org/apache/cassandra/utils/GuidGenerator.java
@@ -17,8 +17,6 @@
*/
package org.apache.cassandra.utils;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.util.Random;
@@ -36,9 +34,9 @@ public class GuidGenerator {
long secureInitializer = mySecureRand.nextLong();
myRand = new Random(secureInitializer);
try {
- s_id = InetAddress.getLocalHost().toString();
+ s_id = FBUtilities.getLocalAddress().toString();
}
- catch (UnknownHostException e) {
+ catch (RuntimeException e) {
throw new AssertionError(e);
}
}
diff --git
a/test/unit/org/apache/cassandra/cql3/validation/operations/ThriftCQLTester.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/ThriftCQLTester.java
index 13d6901..7947317 100644
---
a/test/unit/org/apache/cassandra/cql3/validation/operations/ThriftCQLTester.java
+++
b/test/unit/org/apache/cassandra/cql3/validation/operations/ThriftCQLTester.java
@@ -19,9 +19,7 @@
package org.apache.cassandra.cql3.validation.operations;
import java.io.IOException;
-import java.net.InetAddress;
import java.net.ServerSocket;
-import java.net.UnknownHostException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -29,12 +27,10 @@ import org.junit.BeforeClass;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.dht.ByteOrderedPartitioner;
-import org.apache.cassandra.dht.Murmur3Partitioner;
import org.apache.cassandra.service.*;
import org.apache.cassandra.thrift.*;
+import org.apache.cassandra.utils.FBUtilities;
import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.transport.TFramedTransport;
-import org.apache.thrift.transport.TSocket;
public class ThriftCQLTester extends CQLTester
{
@@ -62,7 +58,7 @@ public class ThriftCQLTester extends CQLTester
if (thriftServer == null || ! thriftServer.isRunning())
{
- thriftServer = new ThriftServer(InetAddress.getLocalHost(),
thriftPort, 50);
+ thriftServer = new ThriftServer(FBUtilities.getLocalAddress(),
thriftPort, 50);
thriftServer.start();
}
}
@@ -78,7 +74,7 @@ public class ThriftCQLTester extends CQLTester
public Cassandra.Client getClient() throws Throwable
{
- return getClient(InetAddress.getLocalHost().getHostName(), thriftPort);
+ return getClient(FBUtilities.getLocalAddress().getHostName(),
thriftPort);
}
public Cassandra.Client getClient(String hostname, int thriftPort)
throws Throwable
diff --git a/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java
b/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java
index 511511b..459956b 100644
--- a/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java
+++ b/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java
@@ -25,9 +25,9 @@ import static org.junit.Assert.*;
import org.junit.Test;
-import java.lang.RuntimeException;
import java.net.InetAddress;
-import java.net.UnknownHostException;
+
+import org.apache.cassandra.utils.FBUtilities;
public class ArrivalWindowTest
{
@@ -36,15 +36,7 @@ public class ArrivalWindowTest
{
final ArrivalWindow windowWithNano = new ArrivalWindow(4);
final long toNano = 1000000L;
- InetAddress ep;
- try
- {
- ep = InetAddress.getLocalHost();
- }
- catch (UnknownHostException e)
- {
- throw new RuntimeException(e);
- }
+ InetAddress ep = FBUtilities.getLocalAddress();
windowWithNano.add(111 * toNano, ep);
windowWithNano.add(222 * toNano, ep);
windowWithNano.add(333 * toNano, ep);
diff --git a/test/unit/org/apache/cassandra/security/SSLFactoryTest.java
b/test/unit/org/apache/cassandra/security/SSLFactoryTest.java
index b3510bd..ca18073 100644
--- a/test/unit/org/apache/cassandra/security/SSLFactoryTest.java
+++ b/test/unit/org/apache/cassandra/security/SSLFactoryTest.java
@@ -21,7 +21,6 @@ package org.apache.cassandra.security;
import static org.junit.Assert.assertArrayEquals;
import java.io.IOException;
-import java.net.InetAddress;
import javax.net.ssl.SSLServerSocket;
@@ -31,6 +30,7 @@ import com.google.common.collect.Lists;
import org.apache.cassandra.config.EncryptionOptions;
import org.apache.cassandra.config.EncryptionOptions.ServerEncryptionOptions;
+import org.apache.cassandra.utils.FBUtilities;
import org.junit.Test;
public class SSLFactoryTest
@@ -62,7 +62,7 @@ public class SSLFactoryTest
};
// enabled ciphers must be a subset of configured ciphers with
identical order
- try (SSLServerSocket socket = SSLFactory.getServerSocket(options,
InetAddress.getLocalHost(), 55123))
+ try (SSLServerSocket socket = SSLFactory.getServerSocket(options,
FBUtilities.getLocalAddress(), 55123))
{
String[] enabled = socket.getEnabledCipherSuites();
String[] wanted =
Iterables.toArray(Iterables.filter(Lists.newArrayList(options.cipher_suites),
diff --git a/test/unit/org/apache/cassandra/triggers/TriggersTest.java
b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
index b0a5aca..3cd0a2c 100644
--- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java
+++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
@@ -17,7 +17,6 @@
*/
package org.apache.cassandra.triggers;
-import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
@@ -35,6 +34,7 @@ import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.RequestExecutionException;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.*;
+import org.apache.cassandra.utils.FBUtilities;
import org.apache.thrift.protocol.TBinaryProtocol;
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
@@ -63,7 +63,7 @@ public class TriggersTest
{
if (thriftServer == null || ! thriftServer.isRunning())
{
- thriftServer = new ThriftServer(InetAddress.getLocalHost(), 9170,
50);
+ thriftServer = new ThriftServer(FBUtilities.getLocalAddress(),
9170, 50);
thriftServer.start();
}
@@ -122,7 +122,7 @@ public class TriggersTest
Cassandra.Client client = new Cassandra.Client(
new TBinaryProtocol(
new
TFramedTransportFactory().openTransport(
-
InetAddress.getLocalHost().getHostName(), 9170)));
+
FBUtilities.getLocalAddress().getHostName(), 9170)));
client.set_keyspace(ksName);
client.insert(bytes(2),
new ColumnParent(cfName),
@@ -138,7 +138,7 @@ public class TriggersTest
Cassandra.Client client = new Cassandra.Client(
new TBinaryProtocol(
new
TFramedTransportFactory().openTransport(
-
InetAddress.getLocalHost().getHostName(), 9170)));
+
FBUtilities.getLocalAddress().getHostName(), 9170)));
client.set_keyspace(ksName);
org.apache.cassandra.thrift.Mutation mutation = new
org.apache.cassandra.thrift.Mutation();
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
@@ -179,7 +179,7 @@ public class TriggersTest
Cassandra.Client client = new Cassandra.Client(
new TBinaryProtocol(
new TFramedTransportFactory().openTransport(
- InetAddress.getLocalHost().getHostName(),
9170)));
+ FBUtilities.getLocalAddress().getHostName(),
9170)));
client.set_keyspace(ksName);
client.cas(bytes(6),
cfName,
@@ -237,7 +237,7 @@ public class TriggersTest
Cassandra.Client client = new Cassandra.Client(
new TBinaryProtocol(
new TFramedTransportFactory().openTransport(
- InetAddress.getLocalHost().getHostName(),
9170)));
+
FBUtilities.getLocalAddress().getHostName(), 9170)));
client.set_keyspace(ksName);
client.cas(bytes(9),
cf,
@@ -262,7 +262,7 @@ public class TriggersTest
Cassandra.Client client = new Cassandra.Client(
new TBinaryProtocol(
new TFramedTransportFactory().openTransport(
- InetAddress.getLocalHost().getHostName(),
9170)));
+
FBUtilities.getLocalAddress().getHostName(), 9170)));
client.set_keyspace(ksName);
client.cas(bytes(10),
cf,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]