[
https://issues.apache.org/jira/browse/OAK-3884?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Philipp Suter updated OAK-3884:
-------------------------------
Attachment: broadcasttest.patch
> Enable BROADCAST for UDPBroadcaster
> -----------------------------------
>
> Key: OAK-3884
> URL: https://issues.apache.org/jira/browse/OAK-3884
> Project: Jackrabbit Oak
> Issue Type: Improvement
> Components: cache
> Affects Versions: 1.3.14
> Environment: OS X
> Reporter: Philipp Suter
> Attachments: broadcasttest.patch
>
>
> It seems that broadcastEncryptedUDP and broadcastUDP test are not working on
> OS X and most likely other *IX based systems due to the fact that the
> loopback network interface (e.g. lo0) is not having a BROADCAST option [1].
> A workaround patch for the unit tests is listed below.
> [1] See answer to:
> http://serverfault.com/questions/554503/how-do-i-add-a-broadcast-ip-to-the-loopback-interface-under-os-x-using-ifconfig
> ===BEGIN PATCH===
> @@ -22,9 +22,14 @@
>
> import java.io.File;
> import java.io.IOException;
> +import java.net.InetAddress;
> +import java.net.InterfaceAddress;
> +import java.net.NetworkInterface;
> +import java.net.SocketException;
> import java.nio.ByteBuffer;
> import java.sql.Timestamp;
> import java.util.ArrayList;
> +import java.util.Enumeration;
> import java.util.Random;
> import java.util.concurrent.Callable;
>
> @@ -37,7 +42,6 @@
> import
> org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster;
> import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
> import org.junit.Assert;
> -import org.junit.Ignore;
> import org.junit.Test;
> import org.slf4j.LoggerFactory;
>
> @@ -150,16 +154,17 @@
> public void broadcastInMemory() throws Exception {
> broadcast("inMemory", 100);
> }
> -
> +
> @Test
> - @Ignore("OAK-2843")
> public void broadcastUDP() throws Exception {
> try {
> - broadcast("udp:sendTo localhost", 50);
> + String localBroadcastIp = getLocalBroadcastAddress();
> + System.out.println("BROADCASTING TO: " + localBroadcastIp);
> + broadcast("udp:sendTo "+localBroadcastIp, 50);
> } catch (AssertionError e) {
> // IPv6 didn't work, so try with IPv4
> - try {
> - broadcast("udp:group 228.6.7.9", 50);
> + broadcast("udp:group 228.6.7.9", 50);
> + try {
> } catch (AssertionError e2) {
> throwBoth(e, e2);
> }
> @@ -167,10 +172,11 @@
> }
>
> @Test
> - @Ignore("OAK-2843")
> public void broadcastEncryptedUDP() throws Exception {
> try {
> - broadcast("udp:group FF78:230::1234;key test;port 9876;sendTo
> localhost;aes", 50);
> + String localBroadcastIp = getLocalBroadcastAddress();
> + System.out.println("BROADCASTING TO: " + localBroadcastIp);
> + broadcast("udp:group FF78:230::1234;key test;port 9876;sendTo
> "+localBroadcastIp+";aes", 50);
> } catch (AssertionError e) {
> try {
> broadcast("udp:group 228.6.7.9;key test;port 9876;aes", 50);
>
> @@ -178,6 +184,26 @@
> throwBoth(e, e2);
> }
> }
> + }
> +
> + private static String getLocalBroadcastAddress(){
> + try {
> + Enumeration<NetworkInterface> interfaces =
> NetworkInterface.getNetworkInterfaces();
> + while (interfaces.hasMoreElements()) {
> + NetworkInterface networkInterface = interfaces.nextElement();
> + if (networkInterface.isLoopback())
> + continue;
> + for (InterfaceAddress interfaceAddress :
> + networkInterface.getInterfaceAddresses()) {
> + InetAddress broadcast = interfaceAddress.getBroadcast();
> + if (broadcast != null)
> + return broadcast.getHostAddress();
> + }
> + }
> + } catch (SocketException e) {
> + e.printStackTrace();
> + }
> + return null;
> }
>
> private static void throwBoth(AssertionError e, AssertionError e2)
> throws AssertionError {
> ===END PATCH===
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)