Author: norman Date: Mon Jun 20 17:37:37 2011 New Revision: 1137715 URL: http://svn.apache.org/viewvc?rev=1137715&view=rev Log: Make sure all found MX-Records are returned. See JAMES-1251
Added: james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/one-mx.bar.zone james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/three-mx.bar.zone james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.differentprio.zone james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.sameprio.zone Modified: james/server/trunk/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java james/server/trunk/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java Modified: james/server/trunk/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java?rev=1137715&r1=1137714&r2=1137715&view=diff ============================================================================== --- james/server/trunk/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java (original) +++ james/server/trunk/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java Mon Jun 20 17:37:37 2011 @@ -293,32 +293,40 @@ public class DNSJavaService implements D int currentPrio = -1; List<String> samePrio = new ArrayList<String>(); for (int i = 0; i < mxAnswers.length; i++) { - boolean same = true; - + boolean same = false; + boolean lastItem = i + 1 == mxAnswers.length; MXRecord mx = mxAnswers[i]; if (i == 0) { currentPrio = mx.getPriority(); - samePrio.add(mx.getTarget().toString()); } else { if (currentPrio == mx.getPriority()) { - samePrio.add(mx.getTarget().toString()); + same = true; } else { same = false; } } - // see if we need to insert the elements now - if (same == false || i + 1 == mxAnswers.length) { + + String mxRecord = mx.getTarget().toString(); + if (same) { + samePrio.add(mxRecord); + } else { + // shuffle entries with same prio + // JAMES-913 + Collections.shuffle(samePrio); + servers.addAll(samePrio); + + samePrio.clear(); + samePrio.add(mxRecord); + + } + + if (lastItem) { // shuffle entries with same prio // JAMES-913 Collections.shuffle(samePrio); servers.addAll(samePrio); - - if (same == false && i + 1 < mxAnswers.length) { - samePrio.clear(); - samePrio.add(mx.getTarget().toString()); - } } - logger.debug(new StringBuffer("Found MX record ").append(mx.getTarget().toString()).toString()); + logger.debug(new StringBuffer("Found MX record ").append(mxRecord).toString()); } return servers; } Modified: james/server/trunk/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java?rev=1137715&r1=1137714&r2=1137715&view=diff ============================================================================== --- james/server/trunk/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java (original) +++ james/server/trunk/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java Mon Jun 20 17:37:37 2011 @@ -37,6 +37,7 @@ import org.xbill.DNS.Zone; import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; import junit.framework.TestCase; @@ -94,6 +95,59 @@ public class DNSJavaServiceTest extends assertEquals("mail.test-zone.com.", res.iterator().next()); } + + /** + * Test for JAMES-1251 + */ + public void testTwoMXSamePrio() throws Exception { + dnsServer.setResolver(null); + dnsServer.setCache(new ZoneCache("two-mx.sameprio.")); + // a.setSearchPath(new String[] { "searchdomain.com." }); + Collection<String> records = dnsServer.findMXRecords("two-mx.sameprio."); + assertEquals(2, records.size()); + assertTrue(records.contains("mx1.two-mx.sameprio.")); + assertTrue(records.contains("mx2.two-mx.sameprio.")); + } + + public void testThreeMX() throws Exception { + dnsServer.setResolver(null); + dnsServer.setCache(new ZoneCache("three-mx.bar.")); + // a.setSearchPath(new String[] { "searchdomain.com." }); + ArrayList<String> records = new ArrayList<String>(dnsServer.findMXRecords("three-mx.bar.")); + assertEquals(3, records.size()); + assertTrue(records.contains("mx1.three-mx.bar.")); + assertTrue(records.contains("mx2.three-mx.bar.")); + assertEquals("mx3.three-mx.bar.", records.get(2)); + + } + + + /** + * Test for JAMES-1251 + */ + public void testTwoMXDifferentPrio() throws Exception { + dnsServer.setResolver(null); + dnsServer.setCache(new ZoneCache("two-mx.differentprio.")); + // a.setSearchPath(new String[] { "searchdomain.com." }); + Collection<String> records = dnsServer.findMXRecords("two-mx.differentprio."); + assertEquals(2, records.size()); + assertTrue(records.contains("mx1.two-mx.differentprio.")); + assertTrue(records.contains("mx2.two-mx.differentprio.")); + + } + + /** + * Test for JAMES-1251 + */ + public void testOneMX() throws Exception { + dnsServer.setResolver(null); + dnsServer.setCache(new ZoneCache("one-mx.bar.")); + // a.setSearchPath(new String[] { "searchdomain.com." }); + Collection<String> records = dnsServer.findMXRecords("one-mx.bar."); + assertEquals(1, records.size()); + assertTrue(records.contains("mx1.one-mx.bar.")); + + } /* * public void testCNAMEasMXrecords() throws Exception { // Zone z = * loadZone("brandilyncollins.com."); dnsServer.setResolver(null); @@ -210,10 +264,6 @@ public class DNSJavaServiceTest extends // return super.lookupRecords(arg0, arg1, arg2); } - public void setCleanInterval(int arg0) { - throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose"); - } - public void setMaxCache(int arg0) { throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose"); } @@ -233,17 +283,10 @@ public class DNSJavaServiceTest extends resolver = r; } - public Resolver getResolver() { - return resolver; - } public void setCache(Cache c) { cache = c; } - - public Cache getCache() { - return cache; - } } } Added: james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/one-mx.bar.zone URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/one-mx.bar.zone?rev=1137715&view=auto ============================================================================== --- james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/one-mx.bar.zone (added) +++ james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/one-mx.bar.zone Mon Jun 20 17:37:37 2011 @@ -0,0 +1,21 @@ +; +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 + +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. +; +one-mx.bar. 14440 IN SOA ns1.hyperdrivedns.net. admin.hyperdrivedns.com. 2004121207 14400 7200 3600000 86400 +one-mx.bar. 14400 IN MX 0 mx1.one-mx.bar. +one-mx.bar. 14400 IN NS ns1.hyperdrivedns.net. Added: james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/three-mx.bar.zone URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/three-mx.bar.zone?rev=1137715&view=auto ============================================================================== --- james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/three-mx.bar.zone (added) +++ james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/three-mx.bar.zone Mon Jun 20 17:37:37 2011 @@ -0,0 +1,23 @@ +; +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 + +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. +; +three-mx.bar. 14440 IN SOA ns1.hyperdrivedns.net. admin.hyperdrivedns.com. 2004121207 14400 7200 3600000 86400 +three-mx.bar. 14400 IN MX 0 mx1.three-mx.bar. +three-mx.bar. 14400 IN MX 0 mx2.three-mx.bar. +three-mx.bar. 14400 IN MX 10 mx3.three-mx.bar. +three-mx.bar. 14400 IN NS ns1.hyperdrivedns.net. Added: james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.differentprio.zone URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.differentprio.zone?rev=1137715&view=auto ============================================================================== --- james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.differentprio.zone (added) +++ james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.differentprio.zone Mon Jun 20 17:37:37 2011 @@ -0,0 +1,23 @@ +; +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 + +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. +; +two-mx.differentprio. 14440 IN SOA ns1.hyperdrivedns.net. admin.hyperdrivedns.com. 2004121207 14400 7200 3600000 86400 +two-mx.differentprio. 14400 IN MX 0 mx1.two-mx.differentprio. +two-mx.differentprio. 14400 IN MX 10 mx2.two-mx.differentprio. +two-mx.differentprio. 14400 IN NS ns1.hyperdrivedns.net. + Added: james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.sameprio.zone URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.sameprio.zone?rev=1137715&view=auto ============================================================================== --- james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.sameprio.zone (added) +++ james/server/trunk/dnsservice-dnsjava/src/test/resources/org/apache/james/dnsservice/dnsjava/two-mx.sameprio.zone Mon Jun 20 17:37:37 2011 @@ -0,0 +1,23 @@ +; +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 + +; Unless required by applicable law or agreed to in writing, +; software distributed under the License is distributed on an +; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +; KIND, either express or implied. See the License for the +; specific language governing permissions and limitations +; under the License. +; +two-mx.sameprio. 14440 IN SOA ns1.hyperdrivedns.net. admin.hyperdrivedns.com. 2004121207 14400 7200 3600000 86400 +two-mx.sameprio. 14400 IN MX 0 mx1.two-mx.sameprio. +two-mx.sameprio. 14400 IN MX 0 mx2.two-mx.sameprio. +two-mx.sameprio. 14400 IN NS ns1.hyperdrivedns.net. + --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org