Skip to content
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

[ISSUE #380] fix latest dubbo version error #381

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

}