-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract compareTo impl to Router interface and concrete Router only responsible for provide priority. #3240
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
133fd5c
extract compareTo impl to Router interface and concrete Router only p…
chickenlj 9c2c60d
add override CompareTo back to compatible Router and add UT
chickenlj bf4800b
Fix compareTo in compatible Router
chickenlj 82c1bcc
Fix possible NPE in Router
chickenlj d154e11
Fix possible NPE in Router
chickenlj f65530c
Change router order in case of getUrl empty
chickenlj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
import java.util.stream.Collectors; | ||
|
||
@Deprecated | ||
public interface Router extends org.apache.dubbo.rpc.cluster.Router { | ||
public interface Router extends org.apache.dubbo.rpc.cluster.Router{ | ||
|
||
@Override | ||
com.alibaba.dubbo.common.URL getUrl(); | ||
|
@@ -36,7 +36,7 @@ <T> List<com.alibaba.dubbo.rpc.Invoker<T>> route(List<com.alibaba.dubbo.rpc.Invo | |
com.alibaba.dubbo.rpc.Invocation invocation) | ||
throws com.alibaba.dubbo.rpc.RpcException; | ||
|
||
int compareTo(com.alibaba.dubbo.rpc.cluster.Router o); | ||
int compareTo(Router o); | ||
|
||
// Add since 2.7.0 | ||
@Override | ||
|
@@ -65,7 +65,11 @@ default int getPriority() { | |
} | ||
|
||
@Override | ||
default int compareTo(org.apache.dubbo.rpc.cluster.Router o) { | ||
return compareTo((Router) o); | ||
default int compareTo (org.apache.dubbo.rpc.cluster.Router o) { | ||
if (!(o instanceof Router)) { | ||
return 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note, a.compareTo(b) is not equivalent b.compareTo(a) |
||
} | ||
|
||
return this.compareTo((Router)o); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
* | ||
*/ | ||
public class CompatibleRouter implements Router { | ||
|
||
@Override | ||
public URL getUrl() { | ||
return null; | ||
|
45 changes: 45 additions & 0 deletions
45
dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter2.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,45 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.rpc.cluster; | ||
|
||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.rpc.Invocation; | ||
import com.alibaba.dubbo.rpc.Invoker; | ||
import com.alibaba.dubbo.rpc.RpcException; | ||
import com.alibaba.dubbo.rpc.cluster.Router; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
*/ | ||
public class CompatibleRouter2 implements Router { | ||
@Override | ||
public URL getUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int compareTo(Router o) { | ||
return 0; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/NewRouter.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 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.rpc.cluster; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.rpc.Invocation; | ||
import org.apache.dubbo.rpc.Invoker; | ||
import org.apache.dubbo.rpc.RpcException; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
*/ | ||
public class NewRouter implements Router { | ||
cvictory marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
public URL getUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isRuntime() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isForce() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return 0; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/RouterTest.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,53 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.rpc.cluster; | ||
|
||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
*/ | ||
public class RouterTest { | ||
|
||
private static List<Router> routers = new ArrayList<>(); | ||
|
||
@BeforeClass | ||
public static void setUp () { | ||
CompatibleRouter compatibleRouter = new CompatibleRouter(); | ||
routers.add(compatibleRouter); | ||
CompatibleRouter2 compatibleRouter2 = new CompatibleRouter2(); | ||
routers.add(compatibleRouter2); | ||
NewRouter newRouter = new NewRouter(); | ||
routers.add(newRouter); | ||
} | ||
|
||
@Test | ||
public void testCompareTo () { | ||
try { | ||
Collections.sort(routers); | ||
Assert.assertTrue(true); | ||
} catch (Exception e) { | ||
Assert.assertFalse(false); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NullPointException for getUrl