WillemJiang closed pull request #454: [JAV-585]Loadbalance rule dynamic 
configuration is not work at some time
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/454
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/handlers/handler-loadbalance/src/main/java/io/servicecomb/loadbalance/LoadbalanceHandler.java
 
b/handlers/handler-loadbalance/src/main/java/io/servicecomb/loadbalance/LoadbalanceHandler.java
index 0d6744b93..61fd9ae68 100644
--- 
a/handlers/handler-loadbalance/src/main/java/io/servicecomb/loadbalance/LoadbalanceHandler.java
+++ 
b/handlers/handler-loadbalance/src/main/java/io/servicecomb/loadbalance/LoadbalanceHandler.java
@@ -92,9 +92,8 @@ public LoadbalanceHandler() {
   public void handle(Invocation invocation, AsyncResponse asyncResp) throws 
Exception {
     String policy = 
Configuration.INSTANCE.getPolicy(invocation.getMicroserviceName());
     String strategy = 
Configuration.INSTANCE.getRuleStrategyName(invocation.getMicroserviceName());
-    boolean isRuleNotChanged = StringUtils.equals(policy,this.policy) && 
StringUtils.equals(strategy, this.strategy);
-    
-    if (!isRuleNotChanged){
+    boolean isRuleNotChanged = isEqual(policy, this.policy) && 
isEqual(strategy, this.strategy);
+    if (!isRuleNotChanged) {
       //??????????????lb??
       synchronized (lock) {
         loadBalancerMap.clear();
@@ -102,7 +101,6 @@ public void handle(Invocation invocation, AsyncResponse 
asyncResp) throws Except
     }
     this.policy = policy;
     this.strategy = strategy;
-
     LoadBalancer loadBalancer = getOrCreateLoadBalancer(invocation);
     // TODO: after all old filter moved to new filter
     // setInvocation method must to be removed
@@ -351,4 +349,8 @@ private void loadFilter(String filter, LoadBalancer lb) {
       }
     }
   }
+
+  public boolean isEqual(String str1, String str2) {
+    return (str1 == null ? str2 == null : str1.equals(str2));
+  }
 }
diff --git 
a/handlers/handler-loadbalance/src/test/java/io/servicecomb/loadbalance/TestLoadbalanceHandler.java
 
b/handlers/handler-loadbalance/src/test/java/io/servicecomb/loadbalance/TestLoadbalanceHandler.java
index c1f1e08f0..c7e2f0ac5 100644
--- 
a/handlers/handler-loadbalance/src/test/java/io/servicecomb/loadbalance/TestLoadbalanceHandler.java
+++ 
b/handlers/handler-loadbalance/src/test/java/io/servicecomb/loadbalance/TestLoadbalanceHandler.java
@@ -437,4 +437,16 @@ public void sendWithRetry() {
 
     // no exception
   }
+  
+  @Test
+  public void testIsEqual(){
+    boolean nullResult = handler.isEqual(null, null);
+    Assert.assertEquals(true, nullResult);  
+    boolean bothNotNullResult = 
handler.isEqual("com.netflix.loadbalancer.RandomRule", 
"com.netflix.loadbalancer.RandomRule");
+    Assert.assertEquals(true, bothNotNullResult);  
+    boolean globalNotNull = handler.isEqual(null, 
"com.netflix.loadbalancer.RandomRule");
+    Assert.assertEquals(false, globalNotNull);  
+    boolean localNotNull = 
handler.isEqual("com.netflix.loadbalancer.RandomRule", null);
+    Assert.assertEquals(false, localNotNull); 
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to