Skip to content

Commit

Permalink
Merge pull request #381 from KamToHung/feat-380
Browse files Browse the repository at this point in the history
[ISSUE #380] fix latest dubbo version error
  • Loading branch information
yanhom1314 committed Dec 30, 2023
2 parents dbce2a3 + 6324d1b commit 1347aef
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ protected void initialize() {
executorRepository = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
}

val data = (ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>>) ReflectionUtil.getFieldValue(
val data = (ConcurrentMap<String, ConcurrentMap<Object, ExecutorService>>) ReflectionUtil.getFieldValue(
DefaultExecutorRepository.class, "data", executorRepository);
if (Objects.isNull(data)) {
return;
}

Map<Integer, ExecutorService> executorMap = data.get(EXECUTOR_SERVICE_COMPONENT_KEY);
Map<Object, ExecutorService> executorMap = data.get(EXECUTOR_SERVICE_COMPONENT_KEY);
if (MapUtils.isNotEmpty(executorMap)) {
executorMap.forEach((k, v) -> {
ThreadPoolExecutor proxy = getProxy(v);
Expand All @@ -124,7 +124,6 @@ protected void initialize() {
});
}
}

private ThreadPoolExecutor getProxy(Executor executor) {
ThreadPoolExecutor proxy;
if (executor instanceof EagerThreadPoolExecutor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.dromara.dynamictp.test.adapter.webserver.dubbo;

import lombok.val;
import org.dromara.dynamictp.common.util.ReflectionUtil;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* dubbo adapter test
*
* @author <a href = "mailto:[email protected]">hongjintao</a>
*/
public class ApacheDubboDtpAdapterTest {

private final ConcurrentMap<String, ConcurrentMap<String, ExecutorService>> newData = new ConcurrentHashMap<>();

private final ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>> oldData = new ConcurrentHashMap<>();

@Test
@SuppressWarnings("unchecked")
public void testOldDubboConcurrentMap() {
ApacheDubboDtpAdapterTest targetObj = new ApacheDubboDtpAdapterTest();
ConcurrentHashMap<String, ExecutorService> newValue = new ConcurrentHashMap<>();
newValue.put("first-pool", Executors.newFixedThreadPool(1));
targetObj.newData.put("name", newValue);
val newData = (ConcurrentMap<String, ConcurrentMap<Object, ExecutorService>>) ReflectionUtil.getFieldValue(
ApacheDubboDtpAdapterTest.class, "newData", targetObj);
assert newData != null;
Assertions.assertEquals("first-pool", newData.get("name").keySet().iterator().next());

ConcurrentHashMap<Integer, ExecutorService> oldValue = new ConcurrentHashMap<>();
oldValue.put(123, Executors.newFixedThreadPool(1));
targetObj.oldData.put("name", oldValue);

val oldData = (ConcurrentMap<String, ConcurrentMap<Object, ExecutorService>>) ReflectionUtil.getFieldValue(
ApacheDubboDtpAdapterTest.class, "oldData", targetObj);
assert oldData != null;
Assertions.assertEquals(123, oldData.get("name").keySet().iterator().next());
}

}

0 comments on commit 1347aef

Please sign in to comment.