repo stringclasses 1k
values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 6
values | commit_sha stringclasses 1k
values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext7/impl/Ext7InitErrorImpl.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext7/impl/Ext7InitErrorImpl.java | /*
* 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.common.extension.ext7.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext7.InitErrorExt;
public class Ext7InitErrorImpl implements InitErrorExt {
static {
if (true) {
throw new RuntimeException("intended!");
}
}
public String echo(URL url, String s) {
return "";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext7/impl/Ext7Impl.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext7/impl/Ext7Impl.java | /*
* 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.common.extension.ext7.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext7.InitErrorExt;
public class Ext7Impl implements InitErrorExt {
public String echo(URL url, String s) {
return "";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt.java | /*
* 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.common.extension.adaptive;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.SPI;
@SPI
public interface HasAdaptiveExt {
@Adaptive
String echo(URL url, String s);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/adaptive/impl/HasAdaptiveExtImpl1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/adaptive/impl/HasAdaptiveExtImpl1.java | /*
* 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.common.extension.adaptive.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.adaptive.HasAdaptiveExt;
public class HasAdaptiveExtImpl1 implements HasAdaptiveExt {
public String echo(URL url, String s) {
return this.getClass().getSimpleName();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/adaptive/impl/HasAdaptiveExt_ManualAdaptive.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/adaptive/impl/HasAdaptiveExt_ManualAdaptive.java | /*
* 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.common.extension.adaptive.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.adaptive.HasAdaptiveExt;
@Adaptive
public class HasAdaptiveExt_ManualAdaptive implements HasAdaptiveExt {
public String echo(URL url, String s) {
HasAdaptiveExt addExt1 =
ExtensionLoader.getExtensionLoader(HasAdaptiveExt.class).getExtension(url.getParameter("key"));
return addExt1.echo(url, s);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/WrappedExtWrapper.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/WrappedExtWrapper.java | /*
* 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.common.extension.ext6_wrap;
public interface WrappedExtWrapper {
WrappedExt getOrigin();
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/WrappedExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/WrappedExt.java | /*
* 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.common.extension.ext6_wrap;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.SPI;
/**
* No Adaptive Method!!
*/
@SPI("impl1")
public interface WrappedExt {
String echo(URL url, String s);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl2.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
public class Ext6Impl2 implements WrappedExt {
public String echo(URL url, String s) {
return "Ext6Impl2-echo";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper1.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExtWrapper;
import java.util.concurrent.atomic.AtomicInteger;
@Wrapper(matches = {"impl1", "impl2"})
public class Ext6Wrapper1 implements WrappedExt, WrappedExtWrapper {
public static AtomicInteger echoCount = new AtomicInteger();
WrappedExt origin;
public Ext6Wrapper1(WrappedExt origin) {
this.origin = origin;
}
public String echo(URL url, String s) {
echoCount.incrementAndGet();
return origin.echo(url, s);
}
@Override
public WrappedExt getOrigin() {
return origin;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper4.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper4.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExtWrapper;
import java.util.concurrent.atomic.AtomicInteger;
@Wrapper(
mismatches = {"impl1", "impl2"},
order = 4)
public class Ext6Wrapper4 implements WrappedExt, WrappedExtWrapper {
public static AtomicInteger echoCount = new AtomicInteger();
WrappedExt origin;
public Ext6Wrapper4(WrappedExt origin) {
this.origin = origin;
}
public String echo(URL url, String s) {
echoCount.incrementAndGet();
return origin.echo(url, s);
}
public WrappedExt getOrigin() {
return origin;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl4.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl4.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
public class Ext6Impl4 implements WrappedExt {
@Override
public String echo(URL url, String s) {
return "Ext6Impl4-echo";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl3.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl3.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
public class Ext6Impl3 implements WrappedExt {
@Override
public String echo(URL url, String s) {
return "Ext6Impl3-echo";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper3.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper3.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExtWrapper;
import java.util.concurrent.atomic.AtomicInteger;
@Wrapper(
matches = {"impl3"},
order = 3)
public class Ext6Wrapper3 implements WrappedExt, WrappedExtWrapper {
public static AtomicInteger echoCount = new AtomicInteger();
WrappedExt origin;
public Ext6Wrapper3(WrappedExt origin) {
this.origin = origin;
}
public String echo(URL url, String s) {
echoCount.incrementAndGet();
return origin.echo(url, s);
}
public WrappedExt getOrigin() {
return origin;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Impl1.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
public class Ext6Impl1 implements WrappedExt {
public String echo(URL url, String s) {
return "Ext6Impl1-echo";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext6_wrap/impl/Ext6Wrapper2.java | /*
* 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.common.extension.ext6_wrap.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExt;
import org.apache.dubbo.common.extension.ext6_wrap.WrappedExtWrapper;
import java.util.concurrent.atomic.AtomicInteger;
@Wrapper(mismatches = {"impl3", "impl4"})
public class Ext6Wrapper2 implements WrappedExt, WrappedExtWrapper {
public static AtomicInteger echoCount = new AtomicInteger();
WrappedExt origin;
public Ext6Wrapper2(WrappedExt origin) {
this.origin = origin;
}
public String echo(URL url, String s) {
echoCount.incrementAndGet();
return origin.echo(url, s);
}
public WrappedExt getOrigin() {
return origin;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/WrapperTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/WrapperTest.java | /*
* 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.common.extension.wrapper;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.wrapper.impl.DemoWrapper;
import org.apache.dubbo.common.extension.wrapper.impl.DemoWrapper2;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* {@link org.apache.dubbo.common.extension.Wrapper} Test
*
* @since 2.7.5
*/
class WrapperTest {
@Test
void testWrapper() {
Demo demoWrapper = ExtensionLoader.getExtensionLoader(Demo.class).getExtension("demo");
assertTrue(demoWrapper instanceof DemoWrapper);
Demo demoWrapper2 = ExtensionLoader.getExtensionLoader(Demo.class).getExtension("demo2");
assertTrue(demoWrapper2 instanceof DemoWrapper2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/Demo.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/Demo.java | /*
* 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.common.extension.wrapper;
import org.apache.dubbo.common.extension.SPI;
@SPI("demo")
public interface Demo {
String echo(String msg);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/impl/DemoImpl.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/impl/DemoImpl.java | /*
* 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.common.extension.wrapper.impl;
import org.apache.dubbo.common.extension.wrapper.Demo;
public class DemoImpl implements Demo {
@Override
public String echo(String msg) {
return msg;
}
public DemoImpl() {}
public DemoImpl(String test) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/impl/DemoWrapper.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/impl/DemoWrapper.java | /*
* 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.common.extension.wrapper.impl;
import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.wrapper.Demo;
@Wrapper(
matches = {"demo"},
mismatches = "demo2")
public class DemoWrapper implements Demo {
private Demo demo;
public DemoWrapper(Demo demo) {
this.demo = demo;
}
public String echo(String msg) {
return demo.echo(msg);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/impl/DemoWrapper2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/wrapper/impl/DemoWrapper2.java | /*
* 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.common.extension.wrapper.impl;
import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.wrapper.Demo;
@Wrapper(
matches = {"demo2"},
mismatches = {"demo"})
public class DemoWrapper2 implements Demo {
private Demo demo;
public DemoWrapper2(Demo demo) {
this.demo = demo;
}
public String echo(String msg) {
return demo.echo(msg);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/SimpleExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/SimpleExt.java | /*
* 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.common.extension.ext1;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.SPI;
/**
* Simple extension, has no wrapper
*/
@SPI("impl1")
public interface SimpleExt {
// @Adaptive example, do not specify a explicit key.
@Adaptive
String echo(URL url, String s);
@Adaptive({"key1", "key2"})
String yell(URL url, String s);
// no @Adaptive
String bang(URL url, int i);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/impl/SimpleExtImpl3.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/impl/SimpleExtImpl3.java | /*
* 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.common.extension.ext1.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext1.SimpleExt;
public class SimpleExtImpl3 implements SimpleExt {
public String echo(URL url, String s) {
return "Ext1Impl3-echo";
}
public String yell(URL url, String s) {
return "Ext1Impl3-yell";
}
public String bang(URL url, int i) {
return "bang3";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/impl/SimpleExtImpl2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/impl/SimpleExtImpl2.java | /*
* 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.common.extension.ext1.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext1.SimpleExt;
public class SimpleExtImpl2 implements SimpleExt {
public String echo(URL url, String s) {
return "Ext1Impl2-echo";
}
public String yell(URL url, String s) {
return "Ext1Impl2-yell";
}
public String bang(URL url, int i) {
return "bang2";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/impl/SimpleExtImpl1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext1/impl/SimpleExtImpl1.java | /*
* 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.common.extension.ext1.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ext1.SimpleExt;
public class SimpleExtImpl1 implements SimpleExt {
public String echo(URL url, String s) {
return "Ext1Impl1-echo";
}
public String yell(URL url, String s) {
return "Ext1Impl1-yell";
}
public String bang(URL url, int i) {
return "bang1";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/compatible/CompatibleExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/compatible/CompatibleExt.java | /*
* 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.common.extension.compatible;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.SPI;
@SPI("impl1")
public interface CompatibleExt {
@Adaptive
String echo(URL url, String s);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/compatible/impl/CompatibleExtImpl1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/compatible/impl/CompatibleExtImpl1.java | /*
* 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.common.extension.compatible.impl;
import org.apache.dubbo.common.Extension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.compatible.CompatibleExt;
@Extension("impl1")
public class CompatibleExtImpl1 implements CompatibleExt {
public String echo(URL url, String s) {
return "Ext1Impl1-echo";
}
public String yell(URL url, String s) {
return "Ext1Impl1-yell";
}
public String bang(URL url, int i) {
return "bang1";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/compatible/impl/CompatibleExtImpl2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/compatible/impl/CompatibleExtImpl2.java | /*
* 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.common.extension.compatible.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.compatible.CompatibleExt;
public class CompatibleExtImpl2 implements CompatibleExt {
public String echo(URL url, String s) {
return "Ext1Impl2-echo";
}
public String yell(URL url, String s) {
return "Ext1Impl2-yell";
}
public String bang(URL url, int i) {
return "bang2";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooFrameworkProvider.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooFrameworkProvider.java | /*
* 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.common.extension.director;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
@SPI(scope = ExtensionScope.FRAMEWORK)
public interface FooFrameworkProvider {
@Adaptive
void process(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooAppProvider.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooAppProvider.java | /*
* 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.common.extension.director;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
@SPI(scope = ExtensionScope.APPLICATION)
public interface FooAppProvider {
@Adaptive
void process(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooAppService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooAppService.java | /*
* 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.common.extension.director;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
@SPI(scope = ExtensionScope.APPLICATION)
public interface FooAppService {
@Adaptive
void process(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooModuleService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooModuleService.java | /*
* 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.common.extension.director;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
@SPI(scope = ExtensionScope.MODULE)
public interface FooModuleService {
@Adaptive
void process(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooModuleProvider.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooModuleProvider.java | /*
* 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.common.extension.director;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
@SPI(scope = ExtensionScope.MODULE)
public interface FooModuleProvider {
@Adaptive
void process(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooFrameworkService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/FooFrameworkService.java | /*
* 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.common.extension.director;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
@SPI(scope = ExtensionScope.FRAMEWORK)
public interface FooFrameworkService {
@Adaptive
void process(URL url);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestFrameworkService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestFrameworkService.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.director.FooAppProvider;
import org.apache.dubbo.common.extension.director.FooFrameworkProvider;
import org.apache.dubbo.common.extension.director.FooFrameworkService;
import org.apache.dubbo.common.extension.director.FooModuleProvider;
public class TestFrameworkService extends BaseTestService implements FooFrameworkService {
private FooFrameworkProvider frameworkProvider;
private FooAppProvider appProvider;
private FooModuleProvider moduleProvider;
public FooFrameworkProvider getFrameworkProvider() {
return frameworkProvider;
}
public void setFrameworkProvider(FooFrameworkProvider frameworkProvider) {
this.frameworkProvider = frameworkProvider;
}
public FooAppProvider getAppProvider() {
return appProvider;
}
public void setAppProvider(FooAppProvider appProvider) {
this.appProvider = appProvider;
}
public FooModuleProvider getModuleProvider() {
return moduleProvider;
}
public void setModuleProvider(FooModuleProvider moduleProvider) {
this.moduleProvider = moduleProvider;
}
@Override
public void process(URL url) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestAppService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestAppService.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.director.FooAppProvider;
import org.apache.dubbo.common.extension.director.FooAppService;
import org.apache.dubbo.common.extension.director.FooFrameworkProvider;
import org.apache.dubbo.common.extension.director.FooFrameworkService;
import org.apache.dubbo.common.extension.director.FooModuleProvider;
public class TestAppService extends BaseTestService implements FooAppService {
private FooFrameworkService frameworkService;
private FooFrameworkProvider frameworkProvider;
private FooAppProvider appProvider;
private FooModuleProvider moduleProvider;
public FooFrameworkService getFrameworkService() {
return frameworkService;
}
public void setFrameworkService(FooFrameworkService frameworkService) {
this.frameworkService = frameworkService;
}
public FooAppProvider getAppProvider() {
return appProvider;
}
public void setAppProvider(FooAppProvider appProvider) {
this.appProvider = appProvider;
}
public FooModuleProvider getModuleProvider() {
return moduleProvider;
}
public void setModuleProvider(FooModuleProvider moduleProvider) {
this.moduleProvider = moduleProvider;
}
public FooFrameworkProvider getFrameworkProvider() {
return frameworkProvider;
}
public void setFrameworkProvider(FooFrameworkProvider frameworkProvider) {
this.frameworkProvider = frameworkProvider;
}
@Override
public void process(URL url) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestFrameworkProvider.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestFrameworkProvider.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.director.FooFrameworkProvider;
public class TestFrameworkProvider implements FooFrameworkProvider {
@Override
public void process(URL url) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestAppProvider.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestAppProvider.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.director.FooAppProvider;
public class TestAppProvider implements FooAppProvider {
@Override
public void process(URL url) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestModuleProvider.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestModuleProvider.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.director.FooModuleProvider;
public class TestModuleProvider implements FooModuleProvider {
public void process(URL url) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestModuleService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/TestModuleService.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.director.FooAppProvider;
import org.apache.dubbo.common.extension.director.FooAppService;
import org.apache.dubbo.common.extension.director.FooFrameworkProvider;
import org.apache.dubbo.common.extension.director.FooFrameworkService;
import org.apache.dubbo.common.extension.director.FooModuleProvider;
import org.apache.dubbo.common.extension.director.FooModuleService;
public class TestModuleService extends BaseTestService implements FooModuleService {
private FooFrameworkService frameworkService;
private FooFrameworkProvider frameworkProvider;
private FooAppService appService;
private FooAppProvider appProvider;
private FooModuleProvider moduleProvider;
public FooFrameworkService getFrameworkService() {
return frameworkService;
}
public void setFrameworkService(FooFrameworkService frameworkService) {
this.frameworkService = frameworkService;
}
public FooAppProvider getAppProvider() {
return appProvider;
}
public void setAppProvider(FooAppProvider appProvider) {
this.appProvider = appProvider;
}
public FooModuleProvider getModuleProvider() {
return moduleProvider;
}
public void setModuleProvider(FooModuleProvider moduleProvider) {
this.moduleProvider = moduleProvider;
}
public FooFrameworkProvider getFrameworkProvider() {
return frameworkProvider;
}
public void setFrameworkProvider(FooFrameworkProvider frameworkProvider) {
this.frameworkProvider = frameworkProvider;
}
public FooAppService getAppService() {
return appService;
}
public void setAppService(FooAppService appService) {
this.appService = appService;
}
@Override
public void process(URL url) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/BaseTestService.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/director/impl/BaseTestService.java | /*
* 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.common.extension.director.impl;
import org.apache.dubbo.common.resource.Disposable;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModelAware;
public class BaseTestService implements ScopeModelAware, Disposable {
private FrameworkModel frameworkModel;
private ApplicationModel applicationModel;
private ModuleModel moduleModel;
private volatile boolean destroyed;
@Override
public void setFrameworkModel(FrameworkModel frameworkModel) {
this.frameworkModel = frameworkModel;
}
@Override
public void setApplicationModel(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
}
@Override
public void setModuleModel(ModuleModel moduleModel) {
this.moduleModel = moduleModel;
}
public FrameworkModel getFrameworkModel() {
return frameworkModel;
}
public ApplicationModel getApplicationModel() {
return applicationModel;
}
public ModuleModel getModuleModel() {
return moduleModel;
}
@Override
public void destroy() {
this.destroyed = true;
}
public boolean isDestroyed() {
return destroyed;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext9_empty/Ext9Empty.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext9_empty/Ext9Empty.java | /*
* 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.common.extension.ext9_empty;
import org.apache.dubbo.common.extension.SPI;
@SPI
public interface Ext9Empty {
void empty();
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext9_empty/impl/Ext9EmptyImpl.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext9_empty/impl/Ext9EmptyImpl.java | /*
* 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.common.extension.ext9_empty.impl;
import org.apache.dubbo.common.extension.ext9_empty.Ext9Empty;
public class Ext9EmptyImpl implements Ext9Empty {
@Override
public void empty() {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext11_no_adaptive/NoAdaptiveExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext11_no_adaptive/NoAdaptiveExt.java | /*
* 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.common.extension.ext11_no_adaptive;
import org.apache.dubbo.common.extension.SPI;
/**
* Has no Adaptive annotation
*/
@SPI
public interface NoAdaptiveExt {
String echo(String s);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext11_no_adaptive/NoAdaptiveExtImpl.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/ext11_no_adaptive/NoAdaptiveExtImpl.java | /*
* 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.common.extension.ext11_no_adaptive;
public class NoAdaptiveExtImpl implements NoAdaptiveExt {
public String echo(String s) {
return "NoAdaptiveExtImpl-echo";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/convert/String2IntegerConverter.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/convert/String2IntegerConverter.java | /*
* 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.common.extension.convert;
import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToIntegerConverter;
/**
* A {@link Converter} implementation of {@link String} to {@link Integer}
*
* @since 2.7.7
*/
public class String2IntegerConverter extends StringToIntegerConverter {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/convert/String2DoubleConverter.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/convert/String2DoubleConverter.java | /*
* 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.common.extension.convert;
import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToDoubleConverter;
/**
* A {@link Converter} implementation of {@link String} to {@link Double}
*
* @since 2.7.7
*/
public class String2DoubleConverter extends StringToDoubleConverter {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/convert/String2BooleanConverter.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/convert/String2BooleanConverter.java | /*
* 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.common.extension.convert;
import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToBooleanConverter;
/**
* A {@link Converter} implementation of {@link String} to {@link Boolean}
*
* @since 2.7.7
*/
public class String2BooleanConverter extends StringToBooleanConverter {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/DuplicatedOverriddenExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/DuplicatedOverriddenExt.java | /*
* 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.common.extension.duplicated;
import org.apache.dubbo.common.extension.SPI;
/**
* This is an interface for testing duplicated extension
*/
@SPI
public interface DuplicatedOverriddenExt {
String echo();
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/DuplicatedWithoutOverriddenExt.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/DuplicatedWithoutOverriddenExt.java | /*
* 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.common.extension.duplicated;
import org.apache.dubbo.common.extension.SPI;
/**
* This is an interface for testing duplicated extension
* see issue: https://github.com/apache/dubbo/issues/3575
*/
@SPI
public interface DuplicatedWithoutOverriddenExt {
String echo();
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedWithoutOverriddenExt2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedWithoutOverriddenExt2.java | /*
* 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.common.extension.duplicated.impl;
import org.apache.dubbo.common.extension.duplicated.DuplicatedWithoutOverriddenExt;
public class DuplicatedWithoutOverriddenExt2 implements DuplicatedWithoutOverriddenExt {
@Override
public String echo() {
return "DuplicatedWithoutOverriddenExt2";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedOverriddenExt2.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedOverriddenExt2.java | /*
* 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.common.extension.duplicated.impl;
import org.apache.dubbo.common.extension.duplicated.DuplicatedOverriddenExt;
public class DuplicatedOverriddenExt2 implements DuplicatedOverriddenExt {
@Override
public String echo() {
return "DuplicatedOverriddenExt2";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedWithoutOverriddenExt1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedWithoutOverriddenExt1.java | /*
* 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.common.extension.duplicated.impl;
import org.apache.dubbo.common.extension.duplicated.DuplicatedWithoutOverriddenExt;
public class DuplicatedWithoutOverriddenExt1 implements DuplicatedWithoutOverriddenExt {
@Override
public String echo() {
return "DuplicatedWithoutOverriddenExt1";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedOverriddenExt1.java | dubbo-common/src/test/java/org/apache/dubbo/common/extension/duplicated/impl/DuplicatedOverriddenExt1.java | /*
* 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.common.extension.duplicated.impl;
import org.apache.dubbo.common.extension.duplicated.DuplicatedOverriddenExt;
public class DuplicatedOverriddenExt1 implements DuplicatedOverriddenExt {
@Override
public String echo() {
return "DuplicatedOverriddenExt1";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/lang/PrioritizedTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/lang/PrioritizedTest.java | /*
* 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.common.lang;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import org.junit.jupiter.api.Test;
import static java.util.Arrays.asList;
import static java.util.Collections.sort;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* {@link Prioritized} Test
*
* @since 2.7.5
*/
class PrioritizedTest {
@Test
void testConstants() {
assertEquals(Integer.MAX_VALUE, Prioritized.MIN_PRIORITY);
assertEquals(Integer.MIN_VALUE, Prioritized.MAX_PRIORITY);
}
@Test
void testGetPriority() {
assertEquals(Prioritized.NORMAL_PRIORITY, new Prioritized() {}.getPriority());
}
@Test
void testComparator() {
List<Object> list = new LinkedList<>();
// All Prioritized
list.add(of(1));
list.add(of(2));
list.add(of(3));
List<Object> copy = new LinkedList<>(list);
sort(list, Prioritized.COMPARATOR);
assertEquals(copy, list);
// MIX non-Prioritized and Prioritized
list.clear();
list.add(1);
list.add(of(2));
list.add(of(1));
sort(list, Prioritized.COMPARATOR);
copy = asList(of(1), of(2), 1);
assertEquals(copy, list);
// All non-Prioritized
list.clear();
list.add(1);
list.add(2);
list.add(3);
sort(list, Prioritized.COMPARATOR);
copy = asList(1, 2, 3);
assertEquals(copy, list);
}
public static PrioritizedValue of(int value) {
return new PrioritizedValue(value);
}
static class PrioritizedValue implements Prioritized {
private final int value;
private PrioritizedValue(int value) {
this.value = value;
}
@Override
public int getPriority() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PrioritizedValue)) return false;
PrioritizedValue that = (PrioritizedValue) o;
return value == that.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/lang/DefaultShutdownHookCallback.java | dubbo-common/src/test/java/org/apache/dubbo/common/lang/DefaultShutdownHookCallback.java | /*
* 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.common.lang;
/**
* Default {@link ShutdownHookCallback}
*
* @since 2.7.5
*/
public class DefaultShutdownHookCallback implements ShutdownHookCallback {
private boolean executed = false;
@Override
public void callback() throws Throwable {
executed = true;
}
public boolean isExecuted() {
return executed;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/lang/ShutdownHookCallbacksTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/lang/ShutdownHookCallbacksTest.java | /*
* 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.common.lang;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* {@link ShutdownHookCallbacks}
*
* @since 2.7.5
*/
class ShutdownHookCallbacksTest {
private ShutdownHookCallbacks callbacks;
@BeforeEach
public void init() {
callbacks = new ShutdownHookCallbacks(ApplicationModel.defaultModel());
}
@Test
void testSingleton() {
assertNotNull(callbacks);
}
@Test
void testCallback() {
callbacks.callback();
DefaultShutdownHookCallback callback = (DefaultShutdownHookCallback)
callbacks.getCallbacks().iterator().next();
assertTrue(callback.isExecuted());
}
@AfterEach
public void destroy() {
callbacks.destroy();
assertTrue(callbacks.getCallbacks().isEmpty());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/logger/LoggerAdapterTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/logger/LoggerAdapterTest.java | /*
* 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.common.logger;
import org.apache.dubbo.common.logger.jcl.JclLogger;
import org.apache.dubbo.common.logger.jcl.JclLoggerAdapter;
import org.apache.dubbo.common.logger.jdk.JdkLogger;
import org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter;
import org.apache.dubbo.common.logger.log4j.Log4jLogger;
import org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter;
import org.apache.dubbo.common.logger.log4j2.Log4j2Logger;
import org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter;
import org.apache.dubbo.common.logger.slf4j.Slf4jLogger;
import org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter;
import java.lang.reflect.InvocationTargetException;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
class LoggerAdapterTest {
static Stream<Arguments> data() {
return Stream.of(
Arguments.of(JclLoggerAdapter.class, JclLogger.class),
Arguments.of(JdkLoggerAdapter.class, JdkLogger.class),
Arguments.of(Log4jLoggerAdapter.class, Log4jLogger.class),
Arguments.of(Slf4jLoggerAdapter.class, Slf4jLogger.class),
Arguments.of(Log4j2LoggerAdapter.class, Log4j2Logger.class));
}
@ParameterizedTest
@MethodSource("data")
void testGetLogger(Class<? extends LoggerAdapter> loggerAdapterClass, Class<? extends Logger> loggerClass)
throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
LoggerAdapter loggerAdapter =
loggerAdapterClass.getDeclaredConstructor().newInstance();
Logger logger = loggerAdapter.getLogger(this.getClass());
assertThat(logger.getClass().isAssignableFrom(loggerClass), is(true));
logger = loggerAdapter.getLogger(this.getClass().getSimpleName());
assertThat(logger.getClass().isAssignableFrom(loggerClass), is(true));
}
@ParameterizedTest
@MethodSource("data")
void testLevel(Class<? extends LoggerAdapter> loggerAdapterClass)
throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
LoggerAdapter loggerAdapter =
loggerAdapterClass.getDeclaredConstructor().newInstance();
for (Level targetLevel : Level.values()) {
loggerAdapter.setLevel(targetLevel);
assertThat(loggerAdapter.getLevel(), is(targetLevel));
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/logger/LoggerFactoryTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/logger/LoggerFactoryTest.java | /*
* 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.common.logger;
import org.apache.dubbo.rpc.model.FrameworkModel;
import java.io.File;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
class LoggerFactoryTest {
@Test
void testLoggerLevel() {
LoggerFactory.setLevel(Level.INFO);
Level level = LoggerFactory.getLevel();
assertThat(level, is(Level.INFO));
}
@Test
void testGetLogFile() {
LoggerFactory.setLoggerAdapter(FrameworkModel.defaultModel(), "slf4j");
File file = LoggerFactory.getFile();
assertThat(file, is(nullValue()));
}
@Test
void testAllLogLevel() {
for (Level targetLevel : Level.values()) {
LoggerFactory.setLevel(targetLevel);
Level level = LoggerFactory.getLevel();
assertThat(level, is(targetLevel));
}
}
@Test
void testGetLogger() {
Logger logger1 = LoggerFactory.getLogger(this.getClass());
Logger logger2 = LoggerFactory.getLogger(this.getClass());
assertThat(logger1, is(logger2));
}
@Test
void shouldReturnSameLogger() {
Logger logger1 = LoggerFactory.getLogger(this.getClass().getName());
Logger logger2 = LoggerFactory.getLogger(this.getClass().getName());
assertThat(logger1, is(logger2));
}
@Test
void shouldReturnSameErrorTypeAwareLogger() {
ErrorTypeAwareLogger logger1 =
LoggerFactory.getErrorTypeAwareLogger(this.getClass().getName());
ErrorTypeAwareLogger logger2 =
LoggerFactory.getErrorTypeAwareLogger(this.getClass().getName());
assertThat(logger1, is(logger2));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/logger/LoggerTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/logger/LoggerTest.java | /*
* 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.common.logger;
import org.apache.dubbo.common.logger.jcl.JclLoggerAdapter;
import org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter;
import org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter;
import org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter;
import org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter;
import org.apache.dubbo.common.logger.support.FailsafeErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.support.FailsafeLogger;
import java.lang.reflect.InvocationTargetException;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
class LoggerTest {
static Stream<Arguments> data() {
return Stream.of(
Arguments.of(JclLoggerAdapter.class),
Arguments.of(JdkLoggerAdapter.class),
Arguments.of(Log4jLoggerAdapter.class),
Arguments.of(Slf4jLoggerAdapter.class),
Arguments.of(Log4j2LoggerAdapter.class));
}
@ParameterizedTest
@MethodSource("data")
void testAllLogMethod(Class<? extends LoggerAdapter> loggerAdapter) throws Exception {
LoggerAdapter adapter = loggerAdapter.getDeclaredConstructor().newInstance();
adapter.setLevel(Level.ALL);
Logger logger =
new FailsafeErrorTypeAwareLogger(adapter.getLogger(FailsafeLogger.class.getName(), this.getClass()));
logger.error("error");
logger.warn("warn");
logger.info("info");
logger.debug("debug");
logger.trace("trace");
logger.error("error:{}", "arg1");
logger.warn("warn:{}", "arg1");
logger.info("info:{}", "arg1");
logger.debug("debug:{}", "arg1");
logger.trace("trace:{}", "arg1");
logger.error(new Exception("error"));
logger.warn(new Exception("warn"));
logger.info(new Exception("info"));
logger.debug(new Exception("debug"));
logger.trace(new Exception("trace"));
logger.error("error", new Exception("error"));
logger.warn("warn", new Exception("warn"));
logger.info("info", new Exception("info"));
logger.debug("debug", new Exception("debug"));
logger.trace("trace", new Exception("trace"));
logger.error("error:{}", "arg1", new Exception("error"));
logger.warn("warn:{}", "arg1", new Exception("warn"));
logger.info("info:{}", "arg1", new Exception("info"));
logger.debug("debug:{}", "arg1", new Exception("debug"));
logger.trace("trace:{}", "arg1", new Exception("trace"));
}
@ParameterizedTest
@MethodSource("data")
void testLevelEnable(Class<? extends LoggerAdapter> loggerAdapter)
throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
LoggerAdapter adapter = loggerAdapter.getDeclaredConstructor().newInstance();
adapter.setLevel(Level.ALL);
Logger logger = adapter.getLogger(this.getClass());
assertThat(logger.isWarnEnabled(), not(nullValue()));
assertThat(logger.isTraceEnabled(), not(nullValue()));
assertThat(logger.isErrorEnabled(), not(nullValue()));
assertThat(logger.isInfoEnabled(), not(nullValue()));
assertThat(logger.isDebugEnabled(), not(nullValue()));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/logger/support/FailsafeErrorTypeAwareLoggerTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/logger/support/FailsafeErrorTypeAwareLoggerTest.java | /*
* 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.common.logger.support;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ADDRESS_INVALID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Tests for FailsafeErrorTypeAwareLogger to test whether it 'ignores' exceptions thrown by logger or not.
*/
class FailsafeErrorTypeAwareLoggerTest {
@Test
void testFailsafeErrorTypeAwareForLoggingMethod() {
Logger failLogger = mock(Logger.class);
FailsafeErrorTypeAwareLogger failsafeLogger = new FailsafeErrorTypeAwareLogger(failLogger);
doThrow(new RuntimeException()).when(failLogger).error(anyString());
doThrow(new RuntimeException()).when(failLogger).warn(anyString());
doThrow(new RuntimeException()).when(failLogger).info(anyString());
doThrow(new RuntimeException()).when(failLogger).debug(anyString());
doThrow(new RuntimeException()).when(failLogger).trace(anyString());
failsafeLogger.error(REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "error");
failsafeLogger.warn(REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "warn");
doThrow(new RuntimeException()).when(failLogger).error(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).warn(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).info(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).debug(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).trace(any(Throwable.class));
failsafeLogger.error(
REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "error", new Exception("error"));
failsafeLogger.warn(
REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "warn", new Exception("warn"));
}
@Test
void testSuccessLogger() {
Logger successLogger = mock(Logger.class);
when(successLogger.isErrorEnabled()).thenReturn(true);
when(successLogger.isWarnEnabled()).thenReturn(true);
FailsafeErrorTypeAwareLogger failsafeLogger = new FailsafeErrorTypeAwareLogger(successLogger);
failsafeLogger.error(REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "error");
failsafeLogger.warn(REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "warn");
verify(successLogger).error(anyString());
verify(successLogger).warn(anyString());
failsafeLogger.error(
REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "error", new Exception("error"));
failsafeLogger.warn(
REGISTRY_ADDRESS_INVALID, "Registry center", "May be it's offline.", "warn", new Exception("warn"));
}
@Test
void testGetLogger() {
Assertions.assertThrows(RuntimeException.class, () -> {
Logger failLogger = mock(Logger.class);
FailsafeErrorTypeAwareLogger failsafeLogger = new FailsafeErrorTypeAwareLogger(failLogger);
doThrow(new RuntimeException()).when(failLogger).error(anyString());
failsafeLogger.getLogger().error("should get error");
});
}
@Test
void testInstructionShownOrNot() {
LoggerFactory.setLoggerAdapter(FrameworkModel.defaultModel(), "jdk");
ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(FailsafeErrorTypeAwareLoggerTest.class);
logger.error(
REGISTRY_ADDRESS_INVALID,
"Registry center",
"May be it's offline.",
"error message",
new Exception("error"));
logger.error(
REGISTRY_ADDRESS_INVALID,
"Registry center",
"May be it's offline.",
"error message",
new Exception("error"));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/logger/support/FailsafeLoggerTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/logger/support/FailsafeLoggerTest.java | /*
* 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.common.logger.support;
import org.apache.dubbo.common.logger.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
class FailsafeLoggerTest {
@Test
void testFailSafeForLoggingMethod() {
Logger failLogger = mock(Logger.class);
FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);
doThrow(new RuntimeException()).when(failLogger).error(anyString());
doThrow(new RuntimeException()).when(failLogger).warn(anyString());
doThrow(new RuntimeException()).when(failLogger).info(anyString());
doThrow(new RuntimeException()).when(failLogger).debug(anyString());
doThrow(new RuntimeException()).when(failLogger).trace(anyString());
failsafeLogger.error("error");
failsafeLogger.warn("warn");
failsafeLogger.info("info");
failsafeLogger.debug("debug");
failsafeLogger.trace("info");
doThrow(new RuntimeException()).when(failLogger).error(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).warn(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).info(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).debug(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).trace(any(Throwable.class));
failsafeLogger.error(new Exception("error"));
failsafeLogger.warn(new Exception("warn"));
failsafeLogger.info(new Exception("info"));
failsafeLogger.debug(new Exception("debug"));
failsafeLogger.trace(new Exception("trace"));
failsafeLogger.error("error", new Exception("error"));
failsafeLogger.warn("warn", new Exception("warn"));
failsafeLogger.info("info", new Exception("info"));
failsafeLogger.debug("debug", new Exception("debug"));
failsafeLogger.trace("trace", new Exception("trace"));
}
@Test
void testSuccessLogger() {
Logger successLogger = mock(Logger.class);
Mockito.when(successLogger.isErrorEnabled()).thenReturn(true);
Mockito.when(successLogger.isWarnEnabled()).thenReturn(true);
Mockito.when(successLogger.isInfoEnabled()).thenReturn(true);
Mockito.when(successLogger.isDebugEnabled()).thenReturn(true);
Mockito.when(successLogger.isTraceEnabled()).thenReturn(true);
FailsafeLogger failsafeLogger = new FailsafeLogger(successLogger);
failsafeLogger.error("error");
failsafeLogger.warn("warn");
failsafeLogger.info("info");
failsafeLogger.debug("debug");
failsafeLogger.trace("info");
verify(successLogger).error(anyString());
verify(successLogger).warn(anyString());
verify(successLogger).info(anyString());
verify(successLogger).debug(anyString());
verify(successLogger).trace(anyString());
failsafeLogger.error(new Exception("error"));
failsafeLogger.warn(new Exception("warn"));
failsafeLogger.info(new Exception("info"));
failsafeLogger.debug(new Exception("debug"));
failsafeLogger.trace(new Exception("trace"));
failsafeLogger.error("error", new Exception("error"));
failsafeLogger.warn("warn", new Exception("warn"));
failsafeLogger.info("info", new Exception("info"));
failsafeLogger.debug("debug", new Exception("debug"));
failsafeLogger.trace("trace", new Exception("trace"));
}
@Test
void testGetLogger() {
Assertions.assertThrows(RuntimeException.class, () -> {
Logger failLogger = mock(Logger.class);
FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);
doThrow(new RuntimeException()).when(failLogger).error(anyString());
failsafeLogger.getLogger().error("should get error");
});
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/logger/slf4j/Slf4jLoggerTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/logger/slf4j/Slf4jLoggerTest.java | /*
* 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.common.logger.slf4j;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.spi.LocationAwareLogger;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times;
class Slf4jLoggerTest {
@Test
void testLocationAwareLogger() {
LocationAwareLogger locationAwareLogger = mock(LocationAwareLogger.class);
Slf4jLogger logger = new Slf4jLogger(locationAwareLogger);
logger.error("error");
logger.warn("warn");
logger.info("info");
logger.debug("debug");
logger.trace("info");
verify(locationAwareLogger, times(5)).log(isNull(), anyString(), anyInt(), anyString(), isNull(), isNull());
logger.error("error:{}", "arg1");
logger.warn("warn:{}", "arg1");
logger.info("info:{}", "arg1");
logger.debug("debug:{}", "arg1");
logger.trace("info:{}", "arg1");
verify(locationAwareLogger, never())
.log(isNull(), anyString(), anyInt(), anyString(), eq(new String[] {"arg1"}), isNull());
Mockito.when(locationAwareLogger.isErrorEnabled()).thenReturn(true);
Mockito.when(locationAwareLogger.isWarnEnabled()).thenReturn(true);
Mockito.when(locationAwareLogger.isInfoEnabled()).thenReturn(true);
Mockito.when(locationAwareLogger.isDebugEnabled()).thenReturn(true);
Mockito.when(locationAwareLogger.isTraceEnabled()).thenReturn(true);
logger.error("error:{}", "arg1");
logger.warn("warn:{}", "arg1");
logger.info("info:{}", "arg1");
logger.debug("debug:{}", "arg1");
logger.trace("info:{}", "arg1");
verify(locationAwareLogger, times(5))
.log(isNull(), anyString(), anyInt(), anyString(), eq(new String[] {"arg1"}), isNull());
logger.error(new Exception("error"));
logger.warn(new Exception("warn"));
logger.info(new Exception("info"));
logger.debug(new Exception("debug"));
logger.trace(new Exception("trace"));
logger.error("error", new Exception("error"));
logger.warn("warn", new Exception("warn"));
logger.info("info", new Exception("info"));
logger.debug("debug", new Exception("debug"));
logger.trace("trace", new Exception("trace"));
verify(locationAwareLogger, times(10))
.log(isNull(), anyString(), anyInt(), anyString(), isNull(), any(Throwable.class));
logger.error("error:{}", "arg1", new Exception("error"));
logger.warn("warn:{}", "arg1", new Exception("warn"));
logger.info("info:{}", "arg1", new Exception("info"));
logger.debug("debug:{}", "arg1", new Exception("debug"));
logger.trace("trace:{}", "arg1", new Exception("trace"));
verify(locationAwareLogger, times(5))
.log(isNull(), anyString(), anyInt(), anyString(), eq(new String[] {"arg1"}), any(Throwable.class));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/resource/GlobalResourcesRepositoryTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/resource/GlobalResourcesRepositoryTest.java | /*
* 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.common.resource;
import java.util.concurrent.ExecutorService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* {@link GlobalResourcesRepository}
*/
class GlobalResourcesRepositoryTest {
@Test
void test() {
GlobalResourcesRepository repository = GlobalResourcesRepository.getInstance();
ExecutorService globalExecutorService = GlobalResourcesRepository.getGlobalExecutorService();
Assertions.assertNotNull(globalExecutorService);
GlobalDisposable globalDisposable = new GlobalDisposable();
GlobalResourcesRepository.registerGlobalDisposable(globalDisposable);
OneOffDisposable oneOffDisposable = new OneOffDisposable();
repository.registerDisposable(oneOffDisposable);
repository.destroy();
Assertions.assertTrue(globalExecutorService.isShutdown());
Assertions.assertTrue(globalDisposable.isDestroyed());
Assertions.assertTrue(oneOffDisposable.isDestroyed());
Assertions.assertTrue(
!GlobalResourcesRepository.getGlobalReusedDisposables().isEmpty());
Assertions.assertTrue(
GlobalResourcesRepository.getGlobalReusedDisposables().contains(globalDisposable));
Assertions.assertTrue(repository.getOneoffDisposables().isEmpty());
}
class GlobalDisposable implements Disposable {
boolean destroyed = false;
@Override
public void destroy() {
destroyed = true;
}
public boolean isDestroyed() {
return destroyed;
}
}
class OneOffDisposable implements Disposable {
boolean destroyed = false;
@Override
public void destroy() {
destroyed = true;
}
public boolean isDestroyed() {
return destroyed;
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java | /*
* 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.common.cache;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class FileCacheStoreTest {
private FileCacheStore cacheStore;
@Test
void testCache() throws Exception {
String directoryPath = getDirectoryOfClassPath();
String filePath = "test-cache.dubbo.cache";
cacheStore = FileCacheStoreFactory.getInstance(directoryPath, filePath);
Map<String, String> properties = cacheStore.loadCache(10);
assertEquals(2, properties.size());
Map<String, String> newProperties = new HashMap<>();
newProperties.put("newKey1", "newValue1");
newProperties.put("newKey2", "newValue2");
newProperties.put("newKey3", "newValue3");
newProperties.put("newKey4", "newValue4");
cacheStore = FileCacheStoreFactory.getInstance(directoryPath, "non-exit.dubbo.cache");
cacheStore.refreshCache(newProperties, "test refresh cache", 0);
Map<String, String> propertiesLimitTo2 = cacheStore.loadCache(2);
assertEquals(2, propertiesLimitTo2.size());
Map<String, String> propertiesLimitTo10 = cacheStore.loadCache(10);
assertEquals(4, propertiesLimitTo10.size());
cacheStore.destroy();
}
@Test
void testFileSizeExceed() throws Exception {
String directoryPath = getDirectoryOfClassPath();
Map<String, String> newProperties = new HashMap<>();
newProperties.put("newKey1", "newValue1");
newProperties.put("newKey2", "newValue2");
newProperties.put("newKey3", "newValue3");
newProperties.put("newKey4", "newValue4");
cacheStore = FileCacheStoreFactory.getInstance(directoryPath, "non-exit.dubbo.cache");
cacheStore.refreshCache(newProperties, "test refresh cache", 2);
Map<String, String> propertiesLimitTo1 = cacheStore.loadCache(2);
assertEquals(0, propertiesLimitTo1.size());
}
private String getDirectoryOfClassPath() throws URISyntaxException {
URL resource = this.getClass().getResource("/log4j2-test.xml");
String path = Paths.get(resource.toURI()).toFile().getAbsolutePath();
int index = path.indexOf("log4j2-test.xml");
String directoryPath = path.substring(0, index);
return directoryPath;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreFactoryTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreFactoryTest.java | /*
* 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.common.cache;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class FileCacheStoreFactoryTest {
@Test
void testSafeName() throws URISyntaxException {
FileCacheStore store1 = FileCacheStoreFactory.getInstance(getDirectoryOfClassPath(), "../../../dubbo");
Assertions.assertEquals(
getDirectoryOfClassPath() + "..%002f..%002f..%002fdubbo.dubbo.cache", getCacheFilePath(store1));
store1.destroy();
FileCacheStore store2 = FileCacheStoreFactory.getInstance(getDirectoryOfClassPath(), "../../../中文");
Assertions.assertEquals(
getDirectoryOfClassPath() + "..%002f..%002f..%002f%4e2d%6587.dubbo.cache", getCacheFilePath(store2));
store2.destroy();
}
@Test
void testPathIsFile() throws URISyntaxException, IOException {
String basePath = getDirectoryOfClassPath();
String filePath = basePath + File.separator + "isFile";
new File(filePath).createNewFile();
Assertions.assertThrows(RuntimeException.class, () -> FileCacheStoreFactory.getInstance(filePath, "dubbo"));
}
@Test
void testCacheContains() throws URISyntaxException {
String classPath = getDirectoryOfClassPath();
FileCacheStore store1 = FileCacheStoreFactory.getInstance(classPath, "testCacheContains");
Assertions.assertNotNull(getCacheFilePath(store1));
getCacheMap().remove(getCacheFilePath(store1));
FileCacheStore store2 = FileCacheStoreFactory.getInstance(classPath, "testCacheContains");
Assertions.assertEquals(FileCacheStore.Empty.class, store2.getClass());
store1.destroy();
store2.destroy();
FileCacheStore store3 = FileCacheStoreFactory.getInstance(classPath, "testCacheContains");
Assertions.assertNotNull(getCacheFilePath(store3));
store3.destroy();
}
private String getDirectoryOfClassPath() throws URISyntaxException {
URL resource = this.getClass().getResource("/log4j2-test.xml");
String path = Paths.get(resource.toURI()).toFile().getAbsolutePath();
int index = path.indexOf("log4j2-test.xml");
String directoryPath = path.substring(0, index);
return directoryPath;
}
private static class ReflectFieldCache {
Field cacheMapField;
Field cacheFilePathField;
}
private static final ReflectFieldCache REFLECT_FIELD_CACHE = new ReflectFieldCache();
private Map<String, FileCacheStore> getCacheMap() {
try {
if (REFLECT_FIELD_CACHE.cacheMapField == null) {
REFLECT_FIELD_CACHE.cacheMapField = FileCacheStoreFactory.class.getDeclaredField("cacheMap");
REFLECT_FIELD_CACHE.cacheMapField.setAccessible(true);
}
return (Map<String, FileCacheStore>) REFLECT_FIELD_CACHE.cacheMapField.get(null);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
private String getCacheFilePath(FileCacheStore cacheStore) {
try {
if (REFLECT_FIELD_CACHE.cacheFilePathField == null) {
REFLECT_FIELD_CACHE.cacheFilePathField = FileCacheStore.class.getDeclaredField("cacheFilePath");
REFLECT_FIELD_CACHE.cacheFilePathField.setAccessible(true);
}
return (String) REFLECT_FIELD_CACHE.cacheFilePathField.get(cacheStore);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/Person.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/Person.java | /*
* 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.common.model;
import java.io.Serializable;
import java.util.Arrays;
public class Person implements Serializable {
byte oneByte = 123;
private String name = "name1";
private int age = 11;
private String[] value = {"value1", "value2"};
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte getOneByte() {
return oneByte;
}
public void setOneByte(byte b) {
this.oneByte = b;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String[] getValue() {
return value;
}
public void setValue(String[] value) {
this.value = value;
}
@Override
public String toString() {
return String.format("Person name(%s) age(%d) byte(%s) [value=%s]", name, age, oneByte, Arrays.toString(value));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + Arrays.hashCode(value);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Person other = (Person) obj;
if (age != other.age) return false;
if (name == null) {
if (other.name != null) return false;
} else if (!name.equals(other.name)) return false;
if (!Arrays.equals(value, other.value)) return false;
return true;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/User.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/User.java | /*
* 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.common.model;
import java.io.Serializable;
import java.util.Objects;
/**
* this class has no nullary constructor and some field is primitive
*/
public class User implements Serializable {
private int age;
private String name;
public User(int age, String name) {
this.age = age;
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return String.format("User name(%s) age(%d) ", name, age);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (name == null) {
if (user.name != null) {
return false;
}
} else if (!name.equals(user.name)) {
return false;
}
return Objects.equals(age, user.age);
}
@Override
public int hashCode() {
return Objects.hash(age, name);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/SerializablePerson.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/SerializablePerson.java | /*
* 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.common.model;
import java.io.Serializable;
import java.util.Arrays;
public class SerializablePerson implements Serializable {
private static final long serialVersionUID = 1L;
byte oneByte = 123;
private String name = "name1";
private int age = 11;
private String[] value = {"value1", "value2"};
public SerializablePerson(char description, boolean adult) {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte getOneByte() {
return oneByte;
}
public void setOneByte(byte b) {
this.oneByte = b;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String[] getValue() {
return value;
}
public void setValue(String[] value) {
this.value = value;
}
@Override
public String toString() {
return String.format("Person name(%s) age(%d) byte(%s) [value=%s]", name, age, oneByte, Arrays.toString(value));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + Arrays.hashCode(value);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SerializablePerson other = (SerializablePerson) obj;
if (age != other.age) return false;
if (name == null) {
if (other.name != null) return false;
} else if (!name.equals(other.name)) return false;
if (!Arrays.equals(value, other.value)) return false;
return true;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Cgeneric.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Cgeneric.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class Cgeneric<T> implements Serializable {
public static String NAME = "C";
private String name = NAME;
private T data;
private Ageneric<T> a;
private Bgeneric<PersonInfo> b;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getName() {
return name;
}
public Ageneric<T> getA() {
return a;
}
public void setA(Ageneric<T> a) {
this.a = a;
}
public Bgeneric<PersonInfo> getB() {
return b;
}
public void setB(Bgeneric<PersonInfo> b) {
this.b = b;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Phone.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Phone.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class Phone implements Serializable {
private static final long serialVersionUID = 4399060521859707703L;
private String country;
private String area;
private String number;
private String extensionNumber;
public Phone() {}
public Phone(String country, String area, String number, String extensionNumber) {
this.country = country;
this.area = area;
this.number = number;
this.extensionNumber = extensionNumber;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getExtensionNumber() {
return extensionNumber;
}
public void setExtensionNumber(String extensionNumber) {
this.extensionNumber = extensionNumber;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((area == null) ? 0 : area.hashCode());
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((extensionNumber == null) ? 0 : extensionNumber.hashCode());
result = prime * result + ((number == null) ? 0 : number.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Phone other = (Phone) obj;
if (area == null) {
if (other.area != null) return false;
} else if (!area.equals(other.area)) return false;
if (country == null) {
if (other.country != null) return false;
} else if (!country.equals(other.country)) return false;
if (extensionNumber == null) {
if (other.extensionNumber != null) return false;
} else if (!extensionNumber.equals(other.extensionNumber)) return false;
if (number == null) {
if (other.number != null) return false;
} else if (!number.equals(other.number)) return false;
return true;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (country != null && country.length() > 0) {
sb.append(country);
sb.append('-');
}
if (area != null && area.length() > 0) {
sb.append(area);
sb.append('-');
}
if (number != null && number.length() > 0) {
sb.append(number);
}
if (extensionNumber != null && extensionNumber.length() > 0) {
sb.append('-');
sb.append(extensionNumber);
}
return sb.toString();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Bgeneric.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Bgeneric.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class Bgeneric<T> implements Serializable {
public static String NAME = "B";
private String name = NAME;
private T data;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getName() {
return name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonInfo.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonInfo.java | /*
* 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.common.model.person;
import java.io.Serializable;
import java.util.List;
public class PersonInfo implements Serializable {
private static final long serialVersionUID = 7443011149612231882L;
List<Phone> phones;
Phone fax;
FullAddress fullAddress;
String mobileNo;
String name;
boolean male;
boolean female;
String department;
String jobTitle;
String homepageUrl;
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}
public boolean isMale() {
return male;
}
public void setMale(boolean male) {
this.male = male;
}
public boolean isFemale() {
return female;
}
public void setFemale(boolean female) {
this.female = female;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Phone getFax() {
return fax;
}
public void setFax(Phone fax) {
this.fax = fax;
}
public FullAddress getFullAddress() {
return fullAddress;
}
public void setFullAddress(FullAddress fullAddress) {
this.fullAddress = fullAddress;
}
public String getHomepageUrl() {
return homepageUrl;
}
public void setHomepageUrl(String homepageUrl) {
this.homepageUrl = homepageUrl;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String getMobileNo() {
return mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((department == null) ? 0 : department.hashCode());
result = prime * result + ((fax == null) ? 0 : fax.hashCode());
result = prime * result + (female ? 1231 : 1237);
result = prime * result + ((fullAddress == null) ? 0 : fullAddress.hashCode());
result = prime * result + ((homepageUrl == null) ? 0 : homepageUrl.hashCode());
result = prime * result + ((jobTitle == null) ? 0 : jobTitle.hashCode());
result = prime * result + (male ? 1231 : 1237);
result = prime * result + ((mobileNo == null) ? 0 : mobileNo.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((phones == null) ? 0 : phones.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
PersonInfo other = (PersonInfo) obj;
if (department == null) {
if (other.department != null) return false;
} else if (!department.equals(other.department)) return false;
if (fax == null) {
if (other.fax != null) return false;
} else if (!fax.equals(other.fax)) return false;
if (female != other.female) return false;
if (fullAddress == null) {
if (other.fullAddress != null) return false;
} else if (!fullAddress.equals(other.fullAddress)) return false;
if (homepageUrl == null) {
if (other.homepageUrl != null) return false;
} else if (!homepageUrl.equals(other.homepageUrl)) return false;
if (jobTitle == null) {
if (other.jobTitle != null) return false;
} else if (!jobTitle.equals(other.jobTitle)) return false;
if (male != other.male) return false;
if (mobileNo == null) {
if (other.mobileNo != null) return false;
} else if (!mobileNo.equals(other.mobileNo)) return false;
if (name == null) {
if (other.name != null) return false;
} else if (!name.equals(other.name)) return false;
if (phones == null) {
if (other.phones != null) return false;
} else if (!phones.equals(other.phones)) return false;
return true;
}
@Override
public String toString() {
return "PersonInfo [phones=" + phones + ", fax=" + fax + ", fullAddress=" + fullAddress
+ ", mobileNo=" + mobileNo + ", name=" + name + ", male=" + male + ", female="
+ female + ", department=" + department + ", jobTitle=" + jobTitle
+ ", homepageUrl=" + homepageUrl + "]";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonMap.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonMap.java | /*
* 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.common.model.person;
import java.util.HashMap;
public class PersonMap extends HashMap<String, String> {
private static final String ID = "1";
private static final String NAME = "hand";
String personId;
String personName;
public String getPersonId() {
return get(ID);
}
public void setPersonId(String personId) {
this.personId = personId;
}
public String getPersonName() {
return get(NAME);
}
public void setPersonName(String personName) {
this.personName = personName;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Dgeneric.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Dgeneric.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class Dgeneric<T, Y, Z> implements Serializable {
public static String NAME = "D";
private String name = NAME;
private T t;
private Y y;
private Z z;
public T getT() {
return t;
}
public void setT(T t) {
this.t = t;
}
public Y getY() {
return y;
}
public void setY(Y y) {
this.y = y;
}
public Z getZ() {
return z;
}
public void setZ(Z z) {
this.z = z;
}
public String getName() {
return name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Ageneric.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/Ageneric.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class Ageneric<T> implements Serializable {
public static String NAME = "A";
private String name = NAME;
private T data;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getName() {
return name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/BigPerson.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/BigPerson.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class BigPerson implements Serializable {
private static final long serialVersionUID = 1L;
String personId;
String loginName;
PersonStatus status;
String email;
String personName;
PersonInfo infoProfile;
public BigPerson() {}
public BigPerson(String id) {
this.personId = id;
}
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
public PersonInfo getInfoProfile() {
return infoProfile;
}
public void setInfoProfile(PersonInfo infoProfile) {
this.infoProfile = infoProfile;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLoginName() {
return this.loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public PersonStatus getStatus() {
return this.status;
}
public void setStatus(PersonStatus status) {
this.status = status;
}
public String getPersonName() {
return personName;
}
public void setPersonName(String personName) {
this.personName = personName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((infoProfile == null) ? 0 : infoProfile.hashCode());
result = prime * result + ((loginName == null) ? 0 : loginName.hashCode());
result = prime * result + ((personName == null) ? 0 : personName.hashCode());
result = prime * result + ((personId == null) ? 0 : personId.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
BigPerson other = (BigPerson) obj;
if (email == null) {
if (other.email != null) return false;
} else if (!email.equals(other.email)) return false;
if (infoProfile == null) {
if (other.infoProfile != null) return false;
} else if (!infoProfile.equals(other.infoProfile)) return false;
if (loginName == null) {
if (other.loginName != null) return false;
} else if (!loginName.equals(other.loginName)) return false;
if (personName == null) {
if (other.personName != null) return false;
} else if (!personName.equals(other.personName)) return false;
if (personId == null) {
if (other.personId != null) return false;
} else if (!personId.equals(other.personId)) return false;
if (status != other.status) return false;
return true;
}
@Override
public String toString() {
return "BigPerson [personId=" + personId + ", loginName=" + loginName + ", status="
+ status + ", email=" + email + ", personName=" + personName + ", infoProfile="
+ infoProfile + "]";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/FullAddress.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/FullAddress.java | /*
* 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.common.model.person;
import java.io.Serializable;
public class FullAddress implements Serializable {
private static final long serialVersionUID = 5163979984269419831L;
private String countryId;
private String countryName;
private String provinceName;
private String cityId;
private String cityName;
private String streetAddress;
private String zipCode;
public FullAddress() {}
public FullAddress(String countryId, String provinceName, String cityId, String streetAddress, String zipCode) {
this.countryId = countryId;
this.countryName = countryId;
this.provinceName = provinceName;
this.cityId = cityId;
this.cityName = cityId;
this.streetAddress = streetAddress;
this.zipCode = zipCode;
}
public FullAddress(
String countryId,
String countryName,
String provinceName,
String cityId,
String cityName,
String streetAddress,
String zipCode) {
this.countryId = countryId;
this.countryName = countryName;
this.provinceName = provinceName;
this.cityId = cityId;
this.cityName = cityName;
this.streetAddress = streetAddress;
this.zipCode = zipCode;
}
public String getCountryId() {
return countryId;
}
public void setCountryId(String countryId) {
this.countryId = countryId;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String getProvinceName() {
return provinceName;
}
public void setProvinceName(String provinceName) {
this.provinceName = provinceName;
}
public String getCityId() {
return cityId;
}
public void setCityId(String cityId) {
this.cityId = cityId;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cityId == null) ? 0 : cityId.hashCode());
result = prime * result + ((cityName == null) ? 0 : cityName.hashCode());
result = prime * result + ((countryId == null) ? 0 : countryId.hashCode());
result = prime * result + ((countryName == null) ? 0 : countryName.hashCode());
result = prime * result + ((provinceName == null) ? 0 : provinceName.hashCode());
result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode());
result = prime * result + ((zipCode == null) ? 0 : zipCode.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
FullAddress other = (FullAddress) obj;
if (cityId == null) {
if (other.cityId != null) return false;
} else if (!cityId.equals(other.cityId)) return false;
if (cityName == null) {
if (other.cityName != null) return false;
} else if (!cityName.equals(other.cityName)) return false;
if (countryId == null) {
if (other.countryId != null) return false;
} else if (!countryId.equals(other.countryId)) return false;
if (countryName == null) {
if (other.countryName != null) return false;
} else if (!countryName.equals(other.countryName)) return false;
if (provinceName == null) {
if (other.provinceName != null) return false;
} else if (!provinceName.equals(other.provinceName)) return false;
if (streetAddress == null) {
if (other.streetAddress != null) return false;
} else if (!streetAddress.equals(other.streetAddress)) return false;
if (zipCode == null) {
if (other.zipCode != null) return false;
} else if (!zipCode.equals(other.zipCode)) return false;
return true;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (countryName != null && countryName.length() > 0) {
sb.append(countryName);
}
if (provinceName != null && provinceName.length() > 0) {
sb.append(' ');
sb.append(provinceName);
}
if (cityName != null && cityName.length() > 0) {
sb.append(' ');
sb.append(cityName);
}
if (streetAddress != null && streetAddress.length() > 0) {
sb.append(' ');
sb.append(streetAddress);
}
return sb.toString();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonStatus.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonStatus.java | /*
* 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.common.model.person;
public enum PersonStatus {
ENABLED,
DISABLED
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/media/Image.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/media/Image.java | /*
* 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.common.model.media;
public class Image implements java.io.Serializable {
private static final long serialVersionUID = 1L;
public String uri;
public String title; // Can be null
public int width;
public int height;
public Size size;
public Image() {}
public Image(String uri, String title, int width, int height, Size size) {
this.height = height;
this.title = title;
this.uri = uri;
this.width = width;
this.size = size;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Image image = (Image) o;
if (height != image.height) return false;
if (width != image.width) return false;
if (size != image.size) return false;
if (title != null ? !title.equals(image.title) : image.title != null) return false;
if (uri != null ? !uri.equals(image.uri) : image.uri != null) return false;
return true;
}
@Override
public int hashCode() {
int result = uri != null ? uri.hashCode() : 0;
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + width;
result = 31 * result + height;
result = 31 * result + (size != null ? size.hashCode() : 0);
return result;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[Image ");
sb.append("uri=").append(uri);
sb.append(", title=").append(title);
sb.append(", width=").append(width);
sb.append(", height=").append(height);
sb.append(", size=").append(size);
sb.append(']');
return sb.toString();
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
public enum Size {
SMALL,
LARGE
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/model/media/Media.java | dubbo-common/src/test/java/org/apache/dubbo/common/model/media/Media.java | /*
* 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.common.model.media;
import java.util.List;
@SuppressWarnings("serial")
public class Media implements java.io.Serializable {
public String uri;
public String title; // Can be unset.
public int width;
public int height;
public String format;
public long duration;
public long size;
public int bitrate; // Can be unset.
public boolean hasBitrate;
public List<String> persons;
public Player player;
public String copyright; // Can be unset.
public Media() {}
public Media(
String uri,
String title,
int width,
int height,
String format,
long duration,
long size,
int bitrate,
boolean hasBitrate,
List<String> persons,
Player player,
String copyright) {
this.uri = uri;
this.title = title;
this.width = width;
this.height = height;
this.format = format;
this.duration = duration;
this.size = size;
this.bitrate = bitrate;
this.hasBitrate = hasBitrate;
this.persons = persons;
this.player = player;
this.copyright = copyright;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Media media = (Media) o;
if (bitrate != media.bitrate) return false;
if (duration != media.duration) return false;
if (hasBitrate != media.hasBitrate) return false;
if (height != media.height) return false;
if (size != media.size) return false;
if (width != media.width) return false;
if (copyright != null ? !copyright.equals(media.copyright) : media.copyright != null) return false;
if (format != null ? !format.equals(media.format) : media.format != null) return false;
if (persons != null ? !persons.equals(media.persons) : media.persons != null) return false;
if (player != media.player) return false;
if (title != null ? !title.equals(media.title) : media.title != null) return false;
if (uri != null ? !uri.equals(media.uri) : media.uri != null) return false;
return true;
}
@Override
public int hashCode() {
int result = uri != null ? uri.hashCode() : 0;
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + width;
result = 31 * result + height;
result = 31 * result + (format != null ? format.hashCode() : 0);
result = 31 * result + (int) (duration ^ (duration >>> 32));
result = 31 * result + (int) (size ^ (size >>> 32));
result = 31 * result + bitrate;
result = 31 * result + (hasBitrate ? 1 : 0);
result = 31 * result + (persons != null ? persons.hashCode() : 0);
result = 31 * result + (player != null ? player.hashCode() : 0);
result = 31 * result + (copyright != null ? copyright.hashCode() : 0);
return result;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[Media ");
sb.append("uri=").append(uri);
sb.append(", title=").append(title);
sb.append(", width=").append(width);
sb.append(", height=").append(height);
sb.append(", format=").append(format);
sb.append(", duration=").append(duration);
sb.append(", size=").append(size);
sb.append(", hasBitrate=").append(hasBitrate);
sb.append(", bitrate=").append(String.valueOf(bitrate));
sb.append(", persons=").append(persons);
sb.append(", player=").append(player);
sb.append(", copyright=").append(copyright);
sb.append(']');
return sb.toString();
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public int getBitrate() {
return bitrate;
}
public void setBitrate(int bitrate) {
this.bitrate = bitrate;
this.hasBitrate = true;
}
public List<String> getPersons() {
return persons;
}
public void setPersons(List<String> persons) {
this.persons = persons;
}
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
public enum Player {
JAVA,
FLASH
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java | /*
* 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.common.version;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.constants.CommonConstants;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Enumeration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class VersionTest {
@Test
void testGetProtocolVersion() {
Assertions.assertEquals(Version.getProtocolVersion(), Version.DEFAULT_DUBBO_PROTOCOL_VERSION);
}
@Test
void testSupportResponseAttachment() {
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.2"));
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.3"));
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.99"));
Assertions.assertFalse(Version.isSupportResponseAttachment("2.1.0"));
Assertions.assertFalse(Version.isSupportResponseAttachment("2.0.0"));
Assertions.assertFalse(Version.isSupportResponseAttachment("1.0.0"));
Assertions.assertFalse(Version.isSupportResponseAttachment("3.0.0"));
Assertions.assertFalse(Version.isSupportResponseAttachment("2.6.6-stable"));
Assertions.assertFalse(Version.isSupportResponseAttachment("2.6.6.RC1"));
Assertions.assertFalse(Version.isSupportResponseAttachment("2.0.contains"));
Assertions.assertFalse(Version.isSupportResponseAttachment("version.string"));
Assertions.assertFalse(Version.isSupportResponseAttachment("prefix2.0"));
}
@Test
void testGetIntVersion() {
Assertions.assertEquals(2060100, Version.getIntVersion("2.6.1"));
Assertions.assertEquals(2060101, Version.getIntVersion("2.6.1.1"));
Assertions.assertEquals(2070001, Version.getIntVersion("2.7.0.1"));
Assertions.assertEquals(2070000, Version.getIntVersion("2.7.0"));
Assertions.assertEquals(Version.HIGHEST_PROTOCOL_VERSION, Version.getIntVersion("2.0.99"));
Assertions.assertEquals(2070000, Version.getIntVersion("2.7.0.RC1"));
Assertions.assertEquals(2070000, Version.getIntVersion("2.7.0-SNAPSHOT"));
Assertions.assertEquals(3000000, Version.getIntVersion("3.0.0-SNAPSHOT"));
Assertions.assertEquals(3010000, Version.getIntVersion("3.1.0"));
}
@Test
void testCompare() {
Assertions.assertEquals(0, Version.compare("3.0.0", "3.0.0"));
Assertions.assertEquals(0, Version.compare("3.0.0-SNAPSHOT", "3.0.0"));
Assertions.assertEquals(1, Version.compare("3.0.0.1", "3.0.0"));
Assertions.assertEquals(1, Version.compare("3.1.0", "3.0.0"));
Assertions.assertEquals(1, Version.compare("3.1.2.3", "3.0.0"));
Assertions.assertEquals(-1, Version.compare("2.9.9.9", "3.0.0"));
Assertions.assertEquals(-1, Version.compare("2.6.3.1", "3.0.0"));
}
@Test
void testIsFramework270OrHigher() {
Assertions.assertTrue(Version.isRelease270OrHigher("2.7.0"));
Assertions.assertTrue(Version.isRelease270OrHigher("2.7.0.1"));
Assertions.assertTrue(Version.isRelease270OrHigher("2.7.0.2"));
Assertions.assertTrue(Version.isRelease270OrHigher("2.8.0"));
Assertions.assertFalse(Version.isRelease270OrHigher("2.6.3"));
Assertions.assertFalse(Version.isRelease270OrHigher("2.6.3.1"));
}
@Test
void testIsFramework263OrHigher() {
Assertions.assertTrue(Version.isRelease263OrHigher("2.7.0"));
Assertions.assertTrue(Version.isRelease263OrHigher("2.7.0.1"));
Assertions.assertTrue(Version.isRelease263OrHigher("2.6.4"));
Assertions.assertFalse(Version.isRelease263OrHigher("2.6.2"));
Assertions.assertFalse(Version.isRelease263OrHigher("2.6.2.1"));
Assertions.assertFalse(Version.isRelease263OrHigher("2.6.1.1"));
Assertions.assertTrue(Version.isRelease263OrHigher("2.6.3"));
Assertions.assertTrue(Version.isRelease263OrHigher("2.6.3.0"));
}
@Test
void testGetVersion()
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> versionClass = reloadVersionClass();
Assertions.assertEquals(
"1.0.0", versionClass.getDeclaredMethod("getVersion").invoke(null));
}
private static Class<?> reloadVersionClass() throws ClassNotFoundException {
ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader classLoader = new ClassLoader(originClassLoader) {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if ("org.apache.dubbo.common.Version".equals(name)) {
return findClass(name);
}
return super.loadClass(name);
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
try {
byte[] bytes = loadClassData(name);
return defineClass(name, bytes, 0, bytes.length);
} catch (Exception e) {
return getParent().loadClass(name);
}
}
public byte[] loadClassData(String className) throws IOException {
className = className.replaceAll("\\.", "/");
String path = Version.class
.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath() + className + ".class";
FileInputStream fileInputStream;
byte[] classBytes;
fileInputStream = new FileInputStream(path);
int length = fileInputStream.available();
classBytes = new byte[length];
fileInputStream.read(classBytes);
fileInputStream.close();
return classBytes;
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (name.equals(CommonConstants.DUBBO_VERSIONS_KEY + "/dubbo-common")) {
return super.getResources("META-INF/test-versions/dubbo-common");
}
return super.getResources(name);
}
};
return classLoader.loadClass("org.apache.dubbo.common.Version");
}
@Test
void testGetLastCommitId()
throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, IllegalAccessException {
Class<?> versionClass = reloadVersionClass();
Assertions.assertEquals(
"82a29fcd674216fe9bea10b6efef3196929dd7ca",
versionClass.getDeclaredMethod("getLastCommitId").invoke(null));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/store/support/SimpleDataStoreTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/store/support/SimpleDataStoreTest.java | /*
* 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.common.store.support;
import org.apache.dubbo.common.store.DataStoreUpdateListener;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SimpleDataStoreTest {
private SimpleDataStore dataStore = new SimpleDataStore();
@Test
void testPutGet() throws Exception {
assertNull(dataStore.get("xxx", "yyy"));
dataStore.put("name", "key", "1");
assertEquals("1", dataStore.get("name", "key"));
assertNull(dataStore.get("xxx", "yyy"));
}
@Test
void testRemove() throws Exception {
dataStore.remove("xxx", "yyy");
dataStore.put("name", "key", "1");
dataStore.remove("name", "key");
assertNull(dataStore.get("name", "key"));
}
@Test
void testGetComponent() throws Exception {
Map<String, Object> map = dataStore.get("component");
assertTrue(map != null && map.isEmpty());
dataStore.put("component", "key", "value");
map = dataStore.get("component");
assertTrue(map != null && map.size() == 1);
dataStore.remove("component", "key");
assertNotEquals(map, dataStore.get("component"));
}
@Test
void testNotify() {
DataStoreUpdateListener listener = Mockito.mock(DataStoreUpdateListener.class);
dataStore.addListener(listener);
ArgumentCaptor<String> componentNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Object> valueCaptor = ArgumentCaptor.forClass(Object.class);
dataStore.put("name", "key", "1");
Mockito.verify(listener).onUpdate(componentNameCaptor.capture(), keyCaptor.capture(), valueCaptor.capture());
assertEquals("name", componentNameCaptor.getValue());
assertEquals("key", keyCaptor.getValue());
assertEquals("1", valueCaptor.getValue());
dataStore.remove("name", "key");
Mockito.verify(listener, Mockito.times(2))
.onUpdate(componentNameCaptor.capture(), keyCaptor.capture(), valueCaptor.capture());
assertEquals("name", componentNameCaptor.getValue());
assertEquals("key", keyCaptor.getValue());
assertNull(valueCaptor.getValue());
dataStore.remove("name2", "key");
Mockito.verify(listener, Mockito.times(0)).onUpdate("name2", "key", null);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/WrapperTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/WrapperTest.java | /*
* 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.common.bytecode;
import org.apache.dubbo.common.utils.ClassUtils;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
class WrapperTest {
private static final Logger logger = LoggerFactory.getLogger(WrapperTest.class);
@Test
void testMain() throws Exception {
Wrapper w = Wrapper.getWrapper(I1.class);
String[] ns = w.getDeclaredMethodNames();
assertEquals(ns.length, 5);
ns = w.getMethodNames();
assertEquals(ns.length, 6);
Object obj = new Impl1();
assertEquals(w.getPropertyValue(obj, "name"), "you name");
w.setPropertyValue(obj, "name", "changed");
assertEquals(w.getPropertyValue(obj, "name"), "changed");
w.invokeMethod(obj, "hello", new Class<?>[] {String.class}, new Object[] {"qianlei"});
w.setPropertyValues(obj, new String[] {"name", "float"}, new Object[] {"mrh", 1.0f});
Object[] propertyValues = w.getPropertyValues(obj, new String[] {"name", "float"});
Assertions.assertEquals(propertyValues.length, 2);
Assertions.assertEquals(propertyValues[0], "mrh");
Assertions.assertEquals(propertyValues[1], 1.0f);
}
// bug: DUBBO-132
@Test
void test_unwantedArgument() throws Exception {
Wrapper w = Wrapper.getWrapper(I1.class);
Object obj = new Impl1();
try {
w.invokeMethod(
obj, "hello", new Class<?>[] {String.class, String.class}, new Object[] {"qianlei", "badboy"});
fail();
} catch (NoSuchMethodException expected) {
}
}
// bug: DUBBO-425
@Test
void test_makeEmptyClass() throws Exception {
Wrapper.getWrapper(EmptyServiceImpl.class);
}
@Test
void testHasMethod() throws Exception {
Wrapper w = Wrapper.getWrapper(I1.class);
Assertions.assertTrue(w.hasMethod("setName"));
Assertions.assertTrue(w.hasMethod("hello"));
Assertions.assertTrue(w.hasMethod("showInt"));
Assertions.assertTrue(w.hasMethod("getFloat"));
Assertions.assertTrue(w.hasMethod("setFloat"));
Assertions.assertFalse(w.hasMethod("setFloatXXX"));
}
@Test
void testWrapperObject() throws Exception {
Wrapper w = Wrapper.getWrapper(Object.class);
Assertions.assertEquals(4, w.getMethodNames().length);
Assertions.assertEquals(4, w.getDeclaredMethodNames().length);
Assertions.assertEquals(0, w.getPropertyNames().length);
Assertions.assertNull(w.getPropertyType(null));
Assertions.assertFalse(w.hasProperty(null));
}
@Test
void testGetPropertyValue() throws Exception {
Assertions.assertThrows(NoSuchPropertyException.class, () -> {
Wrapper w = Wrapper.getWrapper(Object.class);
w.getPropertyValue(null, null);
});
}
@Test
void testSetPropertyValue() throws Exception {
Assertions.assertThrows(NoSuchPropertyException.class, () -> {
Wrapper w = Wrapper.getWrapper(Object.class);
w.setPropertyValue(null, null, null);
});
}
@Test
void testWrapPrimitive() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
Wrapper.getWrapper(Byte.TYPE);
});
}
@Test
void testInvokeWrapperObject() throws Exception {
Wrapper w = Wrapper.getWrapper(Object.class);
Object instance = new Object();
Assertions.assertEquals(instance.getClass(), w.invokeMethod(instance, "getClass", null, null));
Assertions.assertEquals(instance.hashCode(), (int) w.invokeMethod(instance, "hashCode", null, null));
Assertions.assertEquals(instance.toString(), w.invokeMethod(instance, "toString", null, null));
Assertions.assertTrue((boolean)
w.invokeMethod(instance, "equals", new Class[] {instance.getClass()}, new Object[] {instance}));
Assertions.assertThrows(
IllegalArgumentException.class,
() -> w.invokeMethod(
instance, "equals", new Class[] {instance.getClass()}, new Object[] {instance, instance}));
}
@Test
void testNoSuchMethod() throws Exception {
Assertions.assertThrows(NoSuchMethodException.class, () -> {
Wrapper w = Wrapper.getWrapper(Object.class);
w.invokeMethod(new Object(), "__XX__", null, null);
});
}
@Test
void testOverloadMethod() throws Exception {
Wrapper w = Wrapper.getWrapper(I2.class);
assertEquals(2, w.getMethodNames().length);
Impl2 impl = new Impl2();
w.invokeMethod(impl, "setFloat", new Class[] {float.class}, new Object[] {1F});
assertEquals(1F, impl.getFloat1());
assertNull(impl.getFloat2());
w.invokeMethod(impl, "setFloat", new Class[] {Float.class}, new Object[] {2f});
assertEquals(1F, impl.getFloat1());
assertEquals(2F, impl.getFloat2());
w.invokeMethod(impl, "setFloat", new Class[] {Float.class}, new Object[] {null});
assertEquals(1F, impl.getFloat1());
assertNull(impl.getFloat2());
}
@Test
void test_getDeclaredMethodNames_ContainExtendsParentMethods() throws Exception {
assertArrayEquals(
new String[] {
"hello",
},
Wrapper.getWrapper(Parent1.class).getMethodNames());
assertArrayEquals(
new String[] {
"hello",
},
ClassUtils.getMethodNames(Parent1.class));
assertArrayEquals(new String[] {}, Wrapper.getWrapper(Son.class).getDeclaredMethodNames());
assertArrayEquals(new String[] {}, ClassUtils.getDeclaredMethodNames(Son.class));
}
@Test
void test_getMethodNames_ContainExtendsParentMethods() throws Exception {
String[] methodNamesFromWrapepr = Wrapper.getWrapper(Son.class).getMethodNames();
String[] methodNamesFromClassUtils = ClassUtils.getMethodNames(Son.class);
Arrays.sort(methodNamesFromWrapepr);
Arrays.sort(methodNamesFromClassUtils);
assertArrayEquals(new String[] {"hello", "world"}, methodNamesFromWrapepr);
assertArrayEquals(new String[] {"hello", "world"}, methodNamesFromClassUtils);
}
@Test
void testWrapImplClass() {
Wrapper w = Wrapper.getWrapper(Impl0.class);
String[] propertyNames = w.getPropertyNames();
Assertions.assertArrayEquals(propertyNames, new String[] {"a", "b", "c"});
// fields that do not contain the static|final|transient modifier
Assertions.assertFalse(w.hasProperty("f"));
Assertions.assertFalse(w.hasProperty("l"));
Assertions.assertFalse(w.hasProperty("ch"));
// only has public methods, do not contain the private or comes from object methods
Assertions.assertTrue(w.hasMethod("publicMethod"));
Assertions.assertFalse(w.hasMethod("privateMethod"));
Assertions.assertFalse(w.hasMethod("hashcode"));
}
public interface I0 {
String getName();
}
public interface I1 extends I0 {
void setName(String name);
void hello(String name);
int showInt(int v);
float getFloat();
void setFloat(float f);
}
public interface I2 {
void setFloat(float f);
void setFloat(Float f);
}
public interface EmptyService {}
public interface Parent1 {
void hello();
}
public interface Parent2 {
void world();
}
public interface Son extends Parent1, Parent2 {}
public static class Impl0 {
public float a, b, c;
public transient boolean f;
public static long l = 1;
public final char ch = 'c';
private void privateMethod() {}
public void publicMethod() {}
}
public static class Impl1 implements I1 {
private String name = "you name";
private float fv = 0;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void hello(String name) {
logger.info("hello {}", name);
}
public int showInt(int v) {
return v;
}
public float getFloat() {
return fv;
}
public void setFloat(float f) {
fv = f;
}
}
public static class Impl2 implements I2 {
private float float1;
private Float float2;
@Override
public void setFloat(float f) {
this.float1 = f;
}
@Override
public void setFloat(Float f) {
this.float2 = f;
}
public float getFloat1() {
return float1;
}
public Float getFloat2() {
return float2;
}
}
public static class EmptyServiceImpl implements EmptyService {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/ProxyTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/ProxyTest.java | /*
* 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.common.bytecode;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@DisabledForJreRange(min = JRE.JAVA_16)
class ProxyTest {
@Test
void testMain() throws Exception {
Proxy proxy = Proxy.getProxy(ITest.class, ITest.class);
ITest instance = (ITest) proxy.newInstance((proxy1, method, args) -> {
if ("getName".equals(method.getName())) {
assertEquals(args.length, 0);
} else if ("setName".equals(method.getName())) {
assertEquals(args.length, 2);
assertEquals(args[0], "qianlei");
assertEquals(args[1], "hello");
}
return null;
});
assertNull(instance.getName());
instance.setName("qianlei", "hello");
}
@Test
void testCglibProxy() throws Exception {
ITest test = (ITest) Proxy.getProxy(ITest.class).newInstance((proxy, method, args) -> {
return null;
});
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(test.getClass());
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> null);
try {
enhancer.create();
} catch (IllegalArgumentException e) {
e.printStackTrace();
Assertions.fail();
}
}
public interface ITest {
String getName();
void setName(String name, String name2);
static String sayBye() {
return "Bye!";
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java | /*
* 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.common.bytecode;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertTrue;
class MixinTest {
private static final Logger logger = LoggerFactory.getLogger(MixinTest.class);
@Test
void testMain() {
Mixin mixin = Mixin.mixin(new Class[] {I1.class, I2.class, I3.class}, new Class[] {C1.class, C2.class});
Object o = mixin.newInstance(new Object[] {new C1(), new C2()});
assertTrue(o instanceof I1);
assertTrue(o instanceof I2);
assertTrue(o instanceof I3);
((I1) o).m1();
((I2) o).m2();
((I3) o).m3();
}
public interface I1 {
void m1();
}
public interface I2 {
void m2();
}
public interface I3 {
void m3();
}
public class C1 implements Mixin.MixinAware {
public void m1() {
logger.info("c1.m1();");
}
public void m2() {
logger.info("c1.m2();");
}
public void setMixinInstance(Object mi) {
logger.info("c1.setMixinInstance:{}", mi);
}
}
public class C2 implements Mixin.MixinAware {
public void m3() {
logger.info("c2.m3();");
}
public void setMixinInstance(Object mi) {
logger.info("c2.setMixinInstance:{}", mi);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/ClassGeneratorTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/ClassGeneratorTest.java | /*
* 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.common.bytecode;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import javassist.ClassPool;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
interface Builder<T> {
T getName(Bean bean);
void setName(Bean bean, T name);
}
class BaseClass {
public BaseClass() {}
public BaseClass(StringBuilder sb) {
sb.append("constructor comes from BaseClass");
}
public String baseClassMethod() {
return "method comes from BaseClass";
}
}
interface BaseInterface {}
class ClassGeneratorTest {
@Test
void test() throws Exception {
ClassGenerator cg = ClassGenerator.newInstance();
// add className, interface, superClass
String className = BaseClass.class.getPackage().getName() + ".TestClass"
+ UUID.randomUUID().toString().replace("-", "");
cg.setClassName(className);
cg.addInterface(BaseInterface.class);
cg.setSuperClass(BaseClass.class);
// add constructor
cg.addDefaultConstructor();
cg.addConstructor(
Modifier.PUBLIC,
new Class[] {String.class, int.class},
new Class[] {Throwable.class, RuntimeException.class},
"this.strAttr = arg0;this.intAttr = arg1;");
cg.addConstructor(BaseClass.class.getConstructor(StringBuilder.class));
// add field
cg.addField(
"staticAttr", Modifier.PUBLIC | Modifier.STATIC | Modifier.VOLATILE, String.class, "\"defaultVal\"");
cg.addField("strAttr", Modifier.PROTECTED | Modifier.VOLATILE, String.class);
cg.addField("intAttr", Modifier.PRIVATE | Modifier.VOLATILE, int.class);
// add method
cg.addMethod(
"setStrAttr",
Modifier.PUBLIC,
void.class,
new Class[] {String.class, int.class},
new Class[] {Throwable.class, RuntimeException.class},
"this.strAttr = arg0;");
cg.addMethod(
"setIntAttr",
Modifier.PUBLIC,
void.class,
new Class[] {String.class, int.class},
new Class[] {Throwable.class, RuntimeException.class},
"this.intAttr = arg1;");
cg.addMethod(
"getStrAttr",
Modifier.PUBLIC,
String.class,
new Class[] {},
new Class[] {Throwable.class, RuntimeException.class},
"return this.strAttr;");
cg.addMethod(
"getIntAttr",
Modifier.PUBLIC,
int.class,
new Class[] {},
new Class[] {Throwable.class, RuntimeException.class},
"return this.intAttr;");
cg.addMethod(BaseClass.class.getMethod("baseClassMethod"));
// cg.toClass
Class<?> clz = cg.toClass(Bean.class);
// after cg.toClass, the TestClass.class generated by javassist is like the following file content
getClass().getResource("/org/apache/dubbo/common/bytecode/TestClass");
// verify class, superClass, interfaces
Assertions.assertTrue(ClassGenerator.isDynamicClass(clz));
Assertions.assertEquals(clz.getName(), className);
Assertions.assertEquals(clz.getSuperclass(), BaseClass.class);
Assertions.assertArrayEquals(clz.getInterfaces(), new Class[] {ClassGenerator.DC.class, BaseInterface.class});
// get constructors
Constructor<?>[] constructors = clz.getConstructors();
Assertions.assertEquals(constructors.length, 3);
Constructor<?> constructor0 = clz.getConstructor();
Constructor<?> constructor1 = clz.getConstructor(new Class[] {String.class, int.class});
Constructor<?> constructor2 = clz.getConstructor(new Class[] {StringBuilder.class});
Assertions.assertEquals(constructor1.getModifiers(), Modifier.PUBLIC);
Assertions.assertArrayEquals(
constructor1.getExceptionTypes(), new Class[] {Throwable.class, RuntimeException.class});
// get fields
Field staticAttrField = clz.getDeclaredField("staticAttr");
Field strAttrField = clz.getDeclaredField("strAttr");
Field intAttrField = clz.getDeclaredField("intAttr");
Assertions.assertNotNull(staticAttrField);
Assertions.assertNotNull(strAttrField);
Assertions.assertNotNull(intAttrField);
Assertions.assertEquals(staticAttrField.get(null), "defaultVal");
// get methods
Method setStrAttrMethod = clz.getMethod("setStrAttr", new Class[] {String.class, int.class});
Method setIntAttrMethod = clz.getMethod("setIntAttr", new Class[] {String.class, int.class});
Method getStrAttrMethod = clz.getMethod("getStrAttr");
Method getIntAttrMethod = clz.getMethod("getIntAttr");
Method baseClassMethod = clz.getMethod("baseClassMethod");
Assertions.assertNotNull(setStrAttrMethod);
Assertions.assertNotNull(setIntAttrMethod);
Assertions.assertNotNull(getStrAttrMethod);
Assertions.assertNotNull(getIntAttrMethod);
Assertions.assertNotNull(baseClassMethod);
// verify constructor0
Object objByConstructor0 = constructor0.newInstance();
Assertions.assertEquals(getStrAttrMethod.invoke(objByConstructor0), null);
Assertions.assertEquals(getIntAttrMethod.invoke(objByConstructor0), 0);
// verify constructor1
Object objByConstructor1 = constructor1.newInstance("v1", 1);
Assertions.assertEquals(getStrAttrMethod.invoke(objByConstructor1), "v1");
Assertions.assertEquals(getIntAttrMethod.invoke(objByConstructor1), 1);
// verify getter setter method
setStrAttrMethod.invoke(objByConstructor0, "v2", 2);
setIntAttrMethod.invoke(objByConstructor0, "v3", 3);
Assertions.assertEquals(getStrAttrMethod.invoke(objByConstructor0), "v2");
Assertions.assertEquals(getIntAttrMethod.invoke(objByConstructor0), 3);
// verify constructor and method witch comes from baseClass
StringBuilder sb = new StringBuilder();
Object objByConstructor2 = constructor2.newInstance(sb);
Assertions.assertEquals(sb.toString(), "constructor comes from BaseClass");
Object res = baseClassMethod.invoke(objByConstructor2);
Assertions.assertEquals(res, "method comes from BaseClass");
cg.release();
}
@SuppressWarnings("unchecked")
@Test
void testMain() throws Exception {
Bean b = new Bean();
Field fname = Bean.class.getDeclaredField("name");
fname.setAccessible(true);
ClassGenerator cg = ClassGenerator.newInstance();
cg.setClassName(Bean.class.getName() + "$Builder" + UUID.randomUUID().toString());
cg.addInterface(Builder.class);
cg.addField("public static java.lang.reflect.Field FNAME;");
cg.addMethod("public Object getName(" + Bean.class.getName()
+ " o){ boolean[][][] bs = new boolean[0][][]; return (String)FNAME.get($1); }");
cg.addMethod("public void setName(" + Bean.class.getName() + " o, Object name){ FNAME.set($1, $2); }");
cg.addDefaultConstructor();
Class<?> cl = cg.toClass(Bean.class);
cl.getField("FNAME").set(null, fname);
Assertions.assertTrue(cl.getName().startsWith(Bean.class.getName() + "$Builder"));
Builder<String> builder = (Builder<String>) cl.getDeclaredConstructor().newInstance();
Assertions.assertEquals("qianlei", b.getName());
builder.setName(b, "ok");
Assertions.assertEquals("ok", b.getName());
}
@Test
void testMain0() throws Exception {
Bean b = new Bean();
Field fname = Bean.class.getDeclaredField("name");
fname.setAccessible(true);
ClassGenerator cg = ClassGenerator.newInstance();
cg.setClassName(Bean.class.getName() + "$Builder2" + UUID.randomUUID().toString());
cg.addInterface(Builder.class);
cg.addField("FNAME", Modifier.PUBLIC | Modifier.STATIC, java.lang.reflect.Field.class);
cg.addMethod("public Object getName(" + Bean.class.getName()
+ " o){ boolean[][][] bs = new boolean[0][][]; return (String)FNAME.get($1); }");
cg.addMethod("public void setName(" + Bean.class.getName() + " o, Object name){ FNAME.set($1, $2); }");
cg.addDefaultConstructor();
Class<?> cl = cg.toClass(Bean.class);
cl.getField("FNAME").set(null, fname);
Assertions.assertTrue(cl.getName().startsWith(Bean.class.getName() + "$Builder2"));
Builder<String> builder = (Builder<String>) cl.getDeclaredConstructor().newInstance();
Assertions.assertEquals("qianlei", b.getName());
builder.setName(b, "ok");
Assertions.assertEquals("ok", b.getName());
}
@Test
public void test_getClassPool() throws InterruptedException {
int threadCount = 5;
CountDownLatch LATCH = new CountDownLatch(threadCount);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
List<Integer> hashCodeList = new CopyOnWriteArrayList<>();
for (int i = 0; i < threadCount; i++) {
new Thread(new Runnable() {
@Override
public void run() {
ClassPool classPool = ClassGenerator.getClassPool(loader);
int currentHashCode = classPool.hashCode();
hashCodeList.add(currentHashCode);
LATCH.countDown();
}
})
.start();
}
LATCH.await();
Integer firstHashCode = null;
for (Integer currentHashCode : hashCodeList) {
if (firstHashCode == null) {
firstHashCode = currentHashCode;
continue;
}
Assertions.assertTrue(firstHashCode.intValue() == currentHashCode.intValue());
}
}
}
class Bean {
int age = 30;
private String name = "qianlei";
public int getAge() {
return age;
}
public String getName() {
return name;
}
public static volatile String abc = "df";
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/json/GsonUtilsTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/json/GsonUtilsTest.java | /*
* 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.common.json;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class GsonUtilsTest {
@Test
void test1() {
Object user = GsonUtils.fromJson("{'name':'Tom','age':24}", User.class);
Assertions.assertInstanceOf(User.class, user);
Assertions.assertEquals("Tom", ((User) user).getName());
Assertions.assertEquals(24, ((User) user).getAge());
try {
GsonUtils.fromJson("{'name':'Tom','age':}", User.class);
Assertions.fail();
} catch (RuntimeException ex) {
Assertions.assertEquals(
"Generic serialization [gson] Json syntax exception thrown when parsing (message:{'name':'Tom','age':} type:class org.apache.dubbo.common.json.GsonUtilsTest$User) error:com.google.gson.stream.MalformedJsonException: Expected value at line 1 column 21 path $.age\n"
+ "See https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json",
ex.getMessage());
}
}
@Test
void test2() {
ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader();
AtomicReference<List<String>> removedPackages = new AtomicReference<>(Collections.emptyList());
ClassLoader newClassLoader = new ClassLoader(originClassLoader) {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
for (String removedPackage : removedPackages.get()) {
if (name.startsWith(removedPackage)) {
throw new ClassNotFoundException("Test");
}
}
return super.loadClass(name);
}
};
Thread.currentThread().setContextClassLoader(newClassLoader);
// TCCL not found gson
removedPackages.set(Collections.singletonList("com.google.gson"));
GsonUtils.setSupportGson(null);
try {
GsonUtils.fromJson("{'name':'Tom','age':24}", User.class);
Assertions.fail();
} catch (RuntimeException ex) {
Assertions.assertEquals("Gson is not supported. Please import Gson in JVM env.", ex.getMessage());
}
Thread.currentThread().setContextClassLoader(originClassLoader);
GsonUtils.setSupportGson(null);
}
private static class User {
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/json/impl/FastJsonImplTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/json/impl/FastJsonImplTest.java | /*
* 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.common.json.impl;
import java.lang.reflect.Type;
import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.mockito.Answers.CALLS_REAL_METHODS;
class FastJsonImplTest {
private static MockedStatic<JSON> fastjsonMock;
@BeforeAll
static void setup() {
fastjsonMock = Mockito.mockStatic(JSON.class, CALLS_REAL_METHODS);
}
@AfterAll
static void teardown() {
fastjsonMock.close();
}
@Test
void testSupported() {
Assertions.assertTrue(new FastJsonImpl().isSupport());
fastjsonMock.when(() -> JSON.toJSONString(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
Assertions.assertFalse(new FastJsonImpl().isSupport());
fastjsonMock.reset();
fastjsonMock.when(() -> JSON.toJSONString(Mockito.any(), Mockito.any())).thenReturn(null);
Assertions.assertFalse(new FastJsonImpl().isSupport());
fastjsonMock.reset();
fastjsonMock
.when(() -> JSON.parseObject((String) Mockito.any(), (Type) Mockito.any()))
.thenReturn(null);
Assertions.assertFalse(new FastJsonImpl().isSupport());
fastjsonMock.reset();
fastjsonMock
.when(() -> JSON.parseArray(Mockito.any(), (Class) Mockito.any()))
.thenReturn(null);
Assertions.assertFalse(new FastJsonImpl().isSupport());
fastjsonMock.reset();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/json/impl/FastJson2ImplTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/json/impl/FastJson2ImplTest.java | /*
* 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.common.json.impl;
import java.lang.reflect.Type;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.mockito.Answers.CALLS_REAL_METHODS;
class FastJson2ImplTest {
private static MockedStatic<JSON> fastjson2Mock;
@BeforeAll
static void setup() {
fastjson2Mock = Mockito.mockStatic(JSON.class, CALLS_REAL_METHODS);
}
@AfterAll
static void teardown() {
fastjson2Mock.close();
}
@Test
void testSupported() {
Assertions.assertTrue(new FastJson2Impl().isSupport());
fastjson2Mock
.when(() -> JSON.toJSONString(Mockito.any(), (JSONWriter.Feature) Mockito.any()))
.thenThrow(new RuntimeException());
Assertions.assertFalse(new FastJson2Impl().isSupport());
fastjson2Mock.reset();
fastjson2Mock
.when(() -> JSON.toJSONString(Mockito.any(), (JSONWriter.Feature) Mockito.any()))
.thenReturn(null);
Assertions.assertFalse(new FastJson2Impl().isSupport());
fastjson2Mock.reset();
fastjson2Mock
.when(() -> JSON.parseObject((String) Mockito.any(), (Type) Mockito.any()))
.thenReturn(null);
Assertions.assertFalse(new FastJson2Impl().isSupport());
fastjson2Mock.reset();
fastjson2Mock
.when(() -> JSON.parseArray(Mockito.any(), (Class) Mockito.any()))
.thenReturn(null);
Assertions.assertFalse(new FastJson2Impl().isSupport());
fastjson2Mock.reset();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/json/impl/GsonImplTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/json/impl/GsonImplTest.java | /*
* 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.common.json.impl;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import com.google.gson.Gson;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
import org.mockito.Mockito;
public class GsonImplTest {
private static Gson gson = new Gson();
private static AtomicReference<Gson> gsonReference = new AtomicReference<>();
private static MockedConstruction<Gson> gsonMock;
private static AtomicReference<Consumer<Gson>> gsonInit = new AtomicReference<>();
@BeforeAll
static void setup() {
gsonMock = Mockito.mockConstruction(Gson.class, (mock, context) -> {
gsonReference.set(mock);
Mockito.when(mock.toJson((Object) Mockito.any()))
.thenAnswer(invocation -> gson.toJson((Object) invocation.getArgument(0)));
Mockito.when(mock.fromJson(Mockito.anyString(), (Type) Mockito.any()))
.thenAnswer(invocation ->
gson.fromJson((String) invocation.getArgument(0), (Type) invocation.getArgument(1)));
Consumer<Gson> gsonConsumer = gsonInit.get();
if (gsonConsumer != null) {
gsonConsumer.accept(mock);
}
});
}
@AfterAll
static void teardown() {
gsonMock.close();
}
@Test
void testSupported() {
Assertions.assertTrue(new GsonImpl().isSupport());
gsonInit.set(g -> Mockito.when(g.toJson((Object) Mockito.any())).thenThrow(new RuntimeException()));
Assertions.assertFalse(new GsonImpl().isSupport());
gsonInit.set(null);
gsonInit.set(g -> Mockito.when(g.fromJson(Mockito.anyString(), (Type) Mockito.any()))
.thenThrow(new RuntimeException()));
Assertions.assertFalse(new GsonImpl().isSupport());
gsonInit.set(null);
gsonInit.set(g -> Mockito.when(g.toJson((Object) Mockito.any())).thenReturn(null));
Assertions.assertFalse(new GsonImpl().isSupport());
gsonInit.set(null);
gsonInit.set(g -> Mockito.when(g.fromJson(Mockito.anyString(), (Type) Mockito.any()))
.thenReturn(null));
Assertions.assertFalse(new GsonImpl().isSupport());
gsonInit.set(null);
gsonInit.set(g -> Mockito.when(g.fromJson(Mockito.eq("[\"json\"]"), (Type) Mockito.any()))
.thenReturn(null));
Assertions.assertFalse(new GsonImpl().isSupport());
gsonInit.set(null);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/url/URLParamTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/url/URLParamTest.java | /*
* 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.common.url;
import org.apache.dubbo.common.url.component.URLParam;
import org.apache.dubbo.common.utils.CollectionUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class URLParamTest {
@Test
void testParseWithRawParam() {
URLParam urlParam1 = URLParam.parse("aaa=aaa&bbb&version=1.0&default.ccc=123");
Assertions.assertEquals("aaa", urlParam1.getParameter("aaa"));
Assertions.assertEquals("bbb", urlParam1.getParameter("bbb"));
Assertions.assertEquals("1.0", urlParam1.getParameter("version"));
Assertions.assertEquals("123", urlParam1.getParameter("default.ccc"));
Assertions.assertEquals("123", urlParam1.getParameter("ccc"));
Assertions.assertEquals(urlParam1, URLParam.parse(urlParam1.getRawParam()));
Assertions.assertEquals(urlParam1, URLParam.parse(urlParam1.toString()));
URLParam urlParam2 = URLParam.parse("aaa%3dtest", true, null);
Assertions.assertEquals("test", urlParam2.getParameter("aaa"));
Map<String, String> overrideMap = Collections.singletonMap("aaa", "bbb");
URLParam urlParam3 = URLParam.parse("aaa%3dtest", true, overrideMap);
Assertions.assertEquals("bbb", urlParam3.getParameter("aaa"));
URLParam urlParam4 = URLParam.parse("ccc=456&&default.ccc=123");
Assertions.assertEquals("456", urlParam4.getParameter("ccc"));
URLParam urlParam5 = URLParam.parse("version=2.0&&default.version=1.0");
Assertions.assertEquals("2.0", urlParam5.getParameter("version"));
}
@Test
void testParseWithMap() {
Map<String, String> map = new HashMap<>();
map.put("aaa", "aaa");
map.put("bbb", "bbb");
map.put("version", "2.0");
map.put("side", "consumer");
URLParam urlParam1 = URLParam.parse(map);
Assertions.assertEquals("aaa", urlParam1.getParameter("aaa"));
Assertions.assertEquals("bbb", urlParam1.getParameter("bbb"));
Assertions.assertEquals("2.0", urlParam1.getParameter("version"));
Assertions.assertEquals("consumer", urlParam1.getParameter("side"));
Assertions.assertEquals(urlParam1, URLParam.parse(urlParam1.getRawParam()));
map.put("bbb", "ccc");
Assertions.assertEquals("bbb", urlParam1.getParameter("bbb"));
URLParam urlParam2 = URLParam.parse(map);
Assertions.assertEquals("ccc", urlParam2.getParameter("bbb"));
URLParam urlParam3 = URLParam.parse(null, null);
Assertions.assertFalse(urlParam3.hasParameter("aaa"));
Assertions.assertEquals(urlParam3, URLParam.parse(urlParam3.getRawParam()));
}
@Test
void testDefault() {
Map<String, String> map = new HashMap<>();
map.put("aaa", "aaa");
map.put("bbb", "bbb");
map.put("version", "2.0");
map.put("timeout", "1234");
map.put("default.timeout", "5678");
URLParam urlParam1 = URLParam.parse(map);
Assertions.assertEquals("1234", urlParam1.getParameter("timeout"));
Assertions.assertEquals("5678", urlParam1.getParameter("default.timeout"));
map.remove("timeout");
URLParam urlParam2 = URLParam.parse(map);
Assertions.assertEquals("5678", urlParam2.getParameter("timeout"));
Assertions.assertEquals("5678", urlParam2.getParameter("default.timeout"));
URLParam urlParam3 = URLParam.parse("timeout=1234&default.timeout=5678");
Assertions.assertEquals("1234", urlParam3.getParameter("timeout"));
Assertions.assertEquals("5678", urlParam3.getParameter("default.timeout"));
URLParam urlParam4 = URLParam.parse("default.timeout=5678");
Assertions.assertEquals("5678", urlParam4.getParameter("timeout"));
Assertions.assertEquals("5678", urlParam4.getParameter("default.timeout"));
}
@Test
void testGetParameter() {
URLParam urlParam1 = URLParam.parse("aaa=aaa&bbb&version=1.0&default.ccc=123");
Assertions.assertNull(urlParam1.getParameter("abcde"));
URLParam urlParam2 = URLParam.parse("aaa=aaa&bbb&default.ccc=123");
Assertions.assertNull(urlParam2.getParameter("version"));
URLParam urlParam3 = URLParam.parse("aaa=aaa&side=consumer");
Assertions.assertEquals("consumer", urlParam3.getParameter("side"));
URLParam urlParam4 = URLParam.parse("aaa=aaa&side=provider");
Assertions.assertEquals("provider", urlParam4.getParameter("side"));
}
@Test
void testHasParameter() {
URLParam urlParam1 = URLParam.parse("aaa=aaa&side=provider");
Assertions.assertTrue(urlParam1.hasParameter("aaa"));
Assertions.assertFalse(urlParam1.hasParameter("bbb"));
Assertions.assertTrue(urlParam1.hasParameter("side"));
Assertions.assertFalse(urlParam1.hasParameter("version"));
}
@Test
void testRemoveParameters() {
URLParam urlParam1 = URLParam.parse("aaa=aaa&side=provider&version=1.0");
Assertions.assertTrue(urlParam1.hasParameter("aaa"));
Assertions.assertTrue(urlParam1.hasParameter("side"));
Assertions.assertTrue(urlParam1.hasParameter("version"));
URLParam urlParam2 = urlParam1.removeParameters("side");
Assertions.assertFalse(urlParam2.hasParameter("side"));
URLParam urlParam3 = urlParam1.removeParameters("aaa", "version");
Assertions.assertFalse(urlParam3.hasParameter("aaa"));
Assertions.assertFalse(urlParam3.hasParameter("version"));
URLParam urlParam4 = urlParam1.removeParameters();
Assertions.assertTrue(urlParam4.hasParameter("aaa"));
Assertions.assertTrue(urlParam4.hasParameter("side"));
Assertions.assertTrue(urlParam4.hasParameter("version"));
URLParam urlParam5 = urlParam1.clearParameters();
Assertions.assertFalse(urlParam5.hasParameter("aaa"));
Assertions.assertFalse(urlParam5.hasParameter("side"));
Assertions.assertFalse(urlParam5.hasParameter("version"));
URLParam urlParam6 = urlParam1.removeParameters("aaa");
Assertions.assertFalse(urlParam6.hasParameter("aaa"));
URLParam urlParam7 = URLParam.parse("side=consumer").removeParameters("side");
Assertions.assertFalse(urlParam7.hasParameter("side"));
}
@Test
void testAddParameters() {
URLParam urlParam1 = URLParam.parse("aaa=aaa&side=provider");
Assertions.assertTrue(urlParam1.hasParameter("aaa"));
Assertions.assertTrue(urlParam1.hasParameter("side"));
URLParam urlParam2 = urlParam1.addParameter("bbb", "bbb");
Assertions.assertEquals("aaa", urlParam2.getParameter("aaa"));
Assertions.assertEquals("bbb", urlParam2.getParameter("bbb"));
URLParam urlParam3 = urlParam1.addParameter("aaa", "ccc");
Assertions.assertEquals("aaa", urlParam1.getParameter("aaa"));
Assertions.assertEquals("ccc", urlParam3.getParameter("aaa"));
URLParam urlParam4 = urlParam1.addParameter("aaa", "aaa");
Assertions.assertEquals("aaa", urlParam4.getParameter("aaa"));
URLParam urlParam5 = urlParam1.addParameter("version", "0.1");
Assertions.assertEquals("0.1", urlParam5.getParameter("version"));
URLParam urlParam6 = urlParam5.addParameterIfAbsent("version", "0.2");
Assertions.assertEquals("0.1", urlParam6.getParameter("version"));
URLParam urlParam7 = urlParam1.addParameterIfAbsent("version", "0.2");
Assertions.assertEquals("0.2", urlParam7.getParameter("version"));
Map<String, String> map = new HashMap<>();
map.put("version", "1.0");
map.put("side", "provider");
URLParam urlParam8 = urlParam1.addParameters(map);
Assertions.assertEquals("1.0", urlParam8.getParameter("version"));
Assertions.assertEquals("provider", urlParam8.getParameter("side"));
map.put("side", "consumer");
Assertions.assertEquals("provider", urlParam8.getParameter("side"));
URLParam urlParam9 = urlParam8.addParameters(map);
Assertions.assertEquals("consumer", urlParam9.getParameter("side"));
URLParam urlParam10 = urlParam8.addParametersIfAbsent(map);
Assertions.assertEquals("provider", urlParam10.getParameter("side"));
Assertions.assertThrows(IllegalArgumentException.class, () -> urlParam1.addParameter("side", "unrecognized"));
}
@Test
void testURLParamMap() {
URLParam urlParam1 = URLParam.parse("");
Assertions.assertTrue(urlParam1.getParameters().isEmpty());
Assertions.assertEquals(0, urlParam1.getParameters().size());
Assertions.assertFalse(urlParam1.getParameters().containsKey("aaa"));
Assertions.assertFalse(urlParam1.getParameters().containsKey("version"));
Assertions.assertFalse(urlParam1.getParameters().containsKey(new Object()));
Assertions.assertEquals(
new HashMap<>(urlParam1.getParameters()).toString(),
urlParam1.getParameters().toString());
URLParam urlParam2 = URLParam.parse("aaa=aaa&version=1.0");
URLParam.URLParamMap urlParam2Map = (URLParam.URLParamMap) urlParam2.getParameters();
Assertions.assertTrue(urlParam2Map.containsKey("version"));
Assertions.assertFalse(urlParam2Map.containsKey("side"));
Assertions.assertTrue(urlParam2Map.containsValue("1.0"));
Assertions.assertFalse(urlParam2Map.containsValue("2.0"));
Assertions.assertEquals("1.0", urlParam2Map.get("version"));
Assertions.assertEquals("aaa", urlParam2Map.get("aaa"));
Assertions.assertNull(urlParam2Map.get(new Object()));
Assertions.assertEquals(urlParam2, urlParam2Map.getUrlParam());
urlParam2Map.put("version", "1.0");
Assertions.assertEquals(urlParam2, urlParam2Map.getUrlParam());
urlParam2Map.putAll(Collections.singletonMap("version", "1.0"));
Assertions.assertEquals(urlParam2, urlParam2Map.getUrlParam());
urlParam2Map.put("side", "consumer");
Assertions.assertNotEquals(urlParam2, urlParam2Map.getUrlParam());
urlParam2Map = (URLParam.URLParamMap) urlParam2.getParameters();
Assertions.assertEquals(urlParam2, urlParam2Map.getUrlParam());
urlParam2Map.remove("version");
Assertions.assertNotEquals(urlParam2, urlParam2Map.getUrlParam());
Assertions.assertFalse(urlParam2Map.containsValue("version"));
Assertions.assertNull(urlParam2Map.getUrlParam().getParameter("version"));
urlParam2Map = (URLParam.URLParamMap) urlParam2.getParameters();
Assertions.assertEquals(urlParam2, urlParam2Map.getUrlParam());
urlParam2Map.clear();
Assertions.assertTrue(urlParam2Map.isEmpty());
Assertions.assertEquals(0, urlParam2Map.size());
Assertions.assertNull(urlParam2Map.getUrlParam().getParameter("aaa"));
Assertions.assertNull(urlParam2Map.getUrlParam().getParameter("version"));
urlParam2Map = (URLParam.URLParamMap) urlParam2.getParameters();
Assertions.assertEquals(urlParam2, urlParam2Map.getUrlParam());
URLParam urlParam3 = URLParam.parse("aaa=aaa&version=1.0");
Assertions.assertTrue(CollectionUtils.mapEquals(urlParam2Map, urlParam3.getParameters()));
Assertions.assertTrue(CollectionUtils.equals(
urlParam2Map.entrySet(), urlParam3.getParameters().entrySet()));
Assertions.assertTrue(CollectionUtils.equals(
urlParam2Map.keySet(), urlParam3.getParameters().keySet()));
Assertions.assertTrue(CollectionUtils.equals(
urlParam2Map.values(), urlParam3.getParameters().values()));
URLParam urlParam4 = URLParam.parse("aaa=aaa&version=1.0&side=consumer");
Assertions.assertFalse(CollectionUtils.mapEquals(urlParam2Map, urlParam4.getParameters()));
Assertions.assertFalse(CollectionUtils.equals(
urlParam2Map.entrySet(), urlParam4.getParameters().entrySet()));
Assertions.assertFalse(CollectionUtils.equals(
urlParam2Map.keySet(), urlParam4.getParameters().keySet()));
Assertions.assertFalse(CollectionUtils.equals(
urlParam2Map.values(), urlParam4.getParameters().values()));
Set<Map<String, String>> set = new HashSet<>();
set.add(urlParam2Map);
set.add(urlParam3.getParameters());
Assertions.assertEquals(1, set.size());
set.add(urlParam4.getParameters());
Assertions.assertEquals(2, set.size());
URLParam urlParam5 = URLParam.parse("version=1.0");
Assertions.assertEquals(
new HashMap<>(urlParam5.getParameters()).toString(),
urlParam5.getParameters().toString());
}
@Test
void testMethodParameters() {
URLParam urlParam1 = URLParam.parse("aaa.method1=aaa&bbb.method2=bbb");
Assertions.assertEquals("aaa", urlParam1.getAnyMethodParameter("method1"));
Assertions.assertEquals("bbb", urlParam1.getAnyMethodParameter("method2"));
URLParam urlParam2 = URLParam.parse("methods=aaa&aaa.method1=aaa&bbb.method2=bbb");
Assertions.assertEquals("aaa", urlParam2.getAnyMethodParameter("method1"));
Assertions.assertNull(urlParam2.getAnyMethodParameter("method2"));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java | /*
* 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.common.utils;
import org.apache.dubbo.common.constants.CommonConstants;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class NetUtilsTest {
@Test
void testGetRandomPort() {
assertThat(NetUtils.getRandomPort(), greaterThanOrEqualTo(30000));
assertThat(NetUtils.getRandomPort(), greaterThanOrEqualTo(30000));
assertThat(NetUtils.getRandomPort(), greaterThanOrEqualTo(30000));
}
@Test
void testGetAvailablePort() {
assertThat(NetUtils.getAvailablePort(), greaterThan(0));
assertThat(NetUtils.getAvailablePort(12345), greaterThanOrEqualTo(12345));
assertThat(NetUtils.getAvailablePort(-1), greaterThanOrEqualTo(0));
}
@Test
void testValidAddress() {
assertTrue(NetUtils.isValidAddress("10.20.130.230:20880"));
assertFalse(NetUtils.isValidAddress("10.20.130.230"));
assertFalse(NetUtils.isValidAddress("10.20.130.230:666666"));
}
@Test
void testIsInvalidPort() {
assertTrue(NetUtils.isInvalidPort(0));
assertTrue(NetUtils.isInvalidPort(65536));
assertFalse(NetUtils.isInvalidPort(1024));
}
@Test
void testIsLocalHost() {
assertTrue(NetUtils.isLocalHost("localhost"));
assertTrue(NetUtils.isLocalHost("127.1.2.3"));
assertFalse(NetUtils.isLocalHost("128.1.2.3"));
}
@Test
void testIsAnyHost() {
assertTrue(NetUtils.isAnyHost("0.0.0.0"));
assertFalse(NetUtils.isAnyHost("1.1.1.1"));
}
@Test
void testIsInvalidLocalHost() {
assertTrue(NetUtils.isInvalidLocalHost(null));
assertTrue(NetUtils.isInvalidLocalHost(""));
assertTrue(NetUtils.isInvalidLocalHost("localhost"));
assertTrue(NetUtils.isInvalidLocalHost("0.0.0.0"));
assertTrue(NetUtils.isInvalidLocalHost("127.1.2.3"));
assertTrue(NetUtils.isInvalidLocalHost("127.0.0.1"));
assertFalse(NetUtils.isInvalidLocalHost("128.0.0.1"));
}
@Test
void testIsValidLocalHost() {
assertTrue(NetUtils.isValidLocalHost("1.2.3.4"));
assertTrue(NetUtils.isValidLocalHost("128.0.0.1"));
}
@Test
void testGetLocalSocketAddress() {
InetSocketAddress address = NetUtils.getLocalSocketAddress("localhost", 12345);
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(address.getPort(), 12345);
address = NetUtils.getLocalSocketAddress("dubbo-addr", 12345);
assertEquals(address.getHostName(), "dubbo-addr");
assertEquals(address.getPort(), 12345);
}
@Test
void testIsValidAddress() {
assertFalse(NetUtils.isValidV4Address((InetAddress) null));
InetAddress address = mock(InetAddress.class);
when(address.isLoopbackAddress()).thenReturn(true);
assertFalse(NetUtils.isValidV4Address(address));
address = mock(InetAddress.class);
when(address.getHostAddress()).thenReturn("localhost");
assertFalse(NetUtils.isValidV4Address(address));
address = mock(InetAddress.class);
when(address.getHostAddress()).thenReturn("0.0.0.0");
assertFalse(NetUtils.isValidV4Address(address));
address = mock(InetAddress.class);
when(address.getHostAddress()).thenReturn("127.0.0.1");
assertFalse(NetUtils.isValidV4Address(address));
address = mock(InetAddress.class);
when(address.getHostAddress()).thenReturn("1.2.3.4");
assertTrue(NetUtils.isValidV4Address(address));
}
@Test
void testGetLocalHost() {
assertNotNull(NetUtils.getLocalHost());
}
@Test
void testGetLocalAddress() {
InetAddress address = NetUtils.getLocalAddress();
assertNotNull(address);
assertTrue(NetUtils.isValidLocalHost(address.getHostAddress()));
}
@Test
void testFilterLocalHost() {
assertNull(NetUtils.filterLocalHost(null));
assertEquals(NetUtils.filterLocalHost(""), "");
String host = NetUtils.filterLocalHost("dubbo://127.0.0.1:8080/foo");
assertThat(host, equalTo("dubbo://" + NetUtils.getLocalHost() + ":8080/foo"));
host = NetUtils.filterLocalHost("127.0.0.1:8080");
assertThat(host, equalTo(NetUtils.getLocalHost() + ":8080"));
host = NetUtils.filterLocalHost("0.0.0.0");
assertThat(host, equalTo(NetUtils.getLocalHost()));
host = NetUtils.filterLocalHost("88.88.88.88");
assertThat(host, equalTo(host));
}
@Test
void testGetHostName() {
assertNotNull(NetUtils.getHostName("127.0.0.1"));
}
@Test
void testGetIpByHost() {
assertThat(NetUtils.getIpByHost("localhost"), equalTo("127.0.0.1"));
assertThat(NetUtils.getIpByHost("dubbo.local"), equalTo("dubbo.local"));
}
@Test
void testToAddressString() {
InetAddress address = mock(InetAddress.class);
when(address.getHostAddress()).thenReturn("dubbo");
InetSocketAddress socketAddress = new InetSocketAddress(address, 1234);
assertThat(NetUtils.toAddressString(socketAddress), equalTo("dubbo:1234"));
}
@Test
void testToAddress() {
InetSocketAddress address = NetUtils.toAddress("localhost:1234");
assertThat(address.getHostName(), equalTo("localhost"));
assertThat(address.getPort(), equalTo(1234));
address = NetUtils.toAddress("localhost");
assertThat(address.getHostName(), equalTo("localhost"));
assertThat(address.getPort(), equalTo(0));
}
@Test
void testToURL() {
String url = NetUtils.toURL("dubbo", "host", 1234, "foo");
assertThat(url, equalTo("dubbo://host:1234/foo"));
}
@Test
void testIsValidV6Address() {
String saved = System.getProperty("java.net.preferIPv6Addresses", "false");
System.setProperty("java.net.preferIPv6Addresses", "true");
InetAddress address = NetUtils.getLocalAddress();
boolean isPreferIPV6Address = NetUtils.isPreferIPV6Address();
// Restore system property to previous value before executing test
System.setProperty("java.net.preferIPv6Addresses", saved);
assumeTrue(address instanceof Inet6Address);
assertThat(isPreferIPV6Address, equalTo(true));
}
/**
* Mockito starts to support mocking final classes since 2.1.0
* see https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#unmockable
* But enable it will cause other UT to fail.
* Therefore, currently disabling this UT.
*/
@Disabled
@Test
void testNormalizeV6Address() {
Inet6Address address = mock(Inet6Address.class);
when(address.getHostAddress()).thenReturn("fe80:0:0:0:894:aeec:f37d:23e1%en0");
when(address.getScopeId()).thenReturn(5);
InetAddress normalized = NetUtils.normalizeV6Address(address);
assertThat(normalized.getHostAddress(), equalTo("fe80:0:0:0:894:aeec:f37d:23e1%5"));
}
@Test
void testMatchIpRangeMatchWhenIpv4() throws UnknownHostException {
assertTrue(NetUtils.matchIpRange("*.*.*.*", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.*", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.63", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.1-65", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.1-61", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.62", "192.168.1.63", 90));
}
@Test
void testMatchIpRangeMatchWhenIpv6() throws UnknownHostException {
assertTrue(NetUtils.matchIpRange("*.*.*.*", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:*", "234e:0:4567::3d:ff", 90));
assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:ee", "234e:0:4567::3d:ee", 90));
assertTrue(NetUtils.matchIpRange("234e:0:4567::3d:ee", "234e:0:4567::3d:ee", 90));
assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:0-ff", "234e:0:4567::3d:ee", 90));
assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:0-ee", "234e:0:4567::3d:ee", 90));
assertFalse(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:ff", "234e:0:4567::3d:ee", 90));
assertFalse(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:0-ea", "234e:0:4567::3d:ee", 90));
}
@Test
void testMatchIpRangeMatchWhenIpv6Exception() {
IllegalArgumentException thrown = assertThrows(
IllegalArgumentException.class,
() -> NetUtils.matchIpRange("234e:0:4567::3d:*", "234e:0:4567::3d:ff", 90));
assertTrue(thrown.getMessage().contains("If you config ip expression that contains '*'"));
thrown = assertThrows(
IllegalArgumentException.class,
() -> NetUtils.matchIpRange("234e:0:4567:3d", "234e:0:4567::3d:ff", 90));
assertTrue(thrown.getMessage().contains("The host is ipv6, but the pattern is not ipv6 pattern"));
thrown = assertThrows(
IllegalArgumentException.class, () -> NetUtils.matchIpRange("192.168.1.1-65-3", "192.168.1.63", 90));
assertTrue(thrown.getMessage().contains("There is wrong format of ip Address"));
}
@Test
void testMatchIpRangeMatchWhenIpWrongException() {
UnknownHostException thrown = assertThrows(
UnknownHostException.class, () -> NetUtils.matchIpRange("192.168.1.63", "192.168.1.ff", 90));
assertTrue(thrown.getMessage().contains("192.168.1.ff"));
}
@Test
void testMatchIpMatch() throws UnknownHostException {
assertTrue(NetUtils.matchIpExpression("192.168.1.*", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpExpression("192.168.1.192/26", "192.168.1.199", 90));
}
@Test
void testMatchIpv6WithIpPort() throws UnknownHostException {
assertTrue(NetUtils.matchIpRange("[234e:0:4567::3d:ee]", "234e:0:4567::3d:ee", 8090));
assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee]", "234e:0:4567::3d:ee", 8090));
assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee]:8090", "234e:0:4567::3d:ee", 8090));
assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:0-ee]:8090", "234e:0:4567::3d:ee", 8090));
assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee-ff]:8090", "234e:0:4567::3d:ee", 8090));
assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:*]:90", "234e:0:4567::3d:ff", 90));
assertFalse(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee]:7289", "234e:0:4567::3d:ee", 8090));
assertFalse(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee-ff]:8090", "234e:0:4567::3d:ee", 9090));
}
@Test
void testMatchIpv4WithIpPort() throws UnknownHostException {
NumberFormatException thrown = assertThrows(
NumberFormatException.class,
() -> NetUtils.matchIpExpression("192.168.1.192/26:90", "192.168.1.199", 90));
assertTrue(thrown instanceof NumberFormatException);
assertTrue(NetUtils.matchIpRange("*.*.*.*:90", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.*:90", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.63:90", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.63-65:90", "192.168.1.63", 90));
assertTrue(NetUtils.matchIpRange("192.168.1.1-63:90", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("*.*.*.*:80", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.*:80", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.63:80", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.63-65:80", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.1-63:80", "192.168.1.63", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.1-61:90", "192.168.1.62", 90));
assertFalse(NetUtils.matchIpRange("192.168.1.62:90", "192.168.1.63", 90));
}
@Test
void testLocalHost() {
assertEquals(NetUtils.getLocalHost(), NetUtils.getLocalAddress().getHostAddress());
assertTrue(NetUtils.isValidLocalHost(NetUtils.getLocalHost()));
assertFalse(NetUtils.isInvalidLocalHost(NetUtils.getLocalHost()));
}
@Test
void testIsMulticastAddress() {
assertTrue(NetUtils.isMulticastAddress("224.0.0.1"));
assertFalse(NetUtils.isMulticastAddress("127.0.0.1"));
}
@Test
void testFindNetworkInterface() {
assertNotNull(NetUtils.findNetworkInterface());
}
@Test
void testIgnoreAllInterfaces() {
// store the origin ignored interfaces
String originIgnoredInterfaces = this.getIgnoredInterfaces();
try {
// ignore all interfaces
this.setIgnoredInterfaces(".*");
assertNull(NetUtils.findNetworkInterface());
} finally {
// recover the origin ignored interfaces
this.setIgnoredInterfaces(originIgnoredInterfaces);
}
}
@Test
void testIgnoreGivenInterface() {
// store the origin ignored interfaces
String originIgnoredInterfaces = this.getIgnoredInterfaces();
try {
NetworkInterface networkInterface = NetUtils.findNetworkInterface();
assertNotNull(networkInterface);
// ignore the given network interface's display name
this.setIgnoredInterfaces(Pattern.quote(networkInterface.getDisplayName()));
NetworkInterface newNetworkInterface = NetUtils.findNetworkInterface();
if (newNetworkInterface != null) {
assertTrue(!networkInterface.getDisplayName().equals(newNetworkInterface.getDisplayName()));
}
} finally {
// recover the origin ignored interfaces
this.setIgnoredInterfaces(originIgnoredInterfaces);
}
}
@Test
void testIgnoreGivenPrefixInterfaceName() {
// store the origin ignored interfaces
String originIgnoredInterfaces = this.getIgnoredInterfaces();
try {
NetworkInterface networkInterface = NetUtils.findNetworkInterface();
assertNotNull(networkInterface);
// ignore the given prefix network interface's display name
String displayName = networkInterface.getDisplayName();
if (StringUtils.isNotEmpty(displayName) && displayName.length() > 2) {
String ignoredInterfaces = Pattern.quote(displayName.substring(0, 1)) + ".*";
this.setIgnoredInterfaces(ignoredInterfaces);
NetworkInterface newNetworkInterface = NetUtils.findNetworkInterface();
if (newNetworkInterface != null) {
assertTrue(!newNetworkInterface.getDisplayName().startsWith(displayName.substring(0, 1)));
}
}
} finally {
// recover the origin ignored interfaces
this.setIgnoredInterfaces(originIgnoredInterfaces);
}
}
@Test
void testRepeatedStatusChecking() {
int port = NetUtils.getAvailablePort();
for (int i = 0; i < 10000; i++) {
assertFalse(NetUtils.isPortInUsed(port));
}
}
private String getIgnoredInterfaces() {
return SystemPropertyConfigUtils.getSystemProperty(
CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE);
}
private void setIgnoredInterfaces(String ignoredInterfaces) {
if (ignoredInterfaces != null) {
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, ignoredInterfaces);
} else {
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, "");
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtilsTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtilsTest.java | /*
* 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.common.utils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
public class SystemPropertyConfigUtilsTest {
@Test
public void testGetSystemProperty() {
SystemPropertyConfigUtils.setSystemProperty("dubbo.migration.file", "migration.xml");
String value = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file");
assertEquals(value, "migration.xml");
SystemPropertyConfigUtils.clearSystemProperty("dubbo.migration.file");
}
@Test
public void testGetSystemPropertyNotExist() {
assertThrowsExactly(
IllegalStateException.class, () -> SystemPropertyConfigUtils.getSystemProperty("dubbo.not.exist"));
}
@Test
public void testGetSystemPropertyWithDefaultValue() {
String value = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file", "migration.xml");
assertEquals(value, "migration.xml");
}
@Test
public void testSetSystemProperty() {
SystemPropertyConfigUtils.setSystemProperty("dubbo.migration.file", "migration.xml");
String expectValue = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file");
assertEquals(expectValue, "migration.xml");
SystemPropertyConfigUtils.clearSystemProperty("dubbo.migration.file");
}
@Test
public void testClearSystemProperty() {
SystemPropertyConfigUtils.setSystemProperty("dubbo.migration.file", "migration33.xml");
SystemPropertyConfigUtils.clearSystemProperty("dubbo.migration.file");
String expectValue = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file");
assertNull(expectValue);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ClassLoaderResourceLoaderTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/ClassLoaderResourceLoaderTest.java | /*
* 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.common.utils;
import org.apache.dubbo.common.extension.DubboInternalLoadingStrategy;
import org.apache.dubbo.common.extension.director.FooAppProvider;
import org.apache.dubbo.common.resource.GlobalResourcesRepository;
import java.net.URL;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* {@link ClassLoaderResourceLoader}
*/
class ClassLoaderResourceLoaderTest {
@Test
void test() throws InterruptedException {
DubboInternalLoadingStrategy dubboInternalLoadingStrategy = new DubboInternalLoadingStrategy();
String directory = dubboInternalLoadingStrategy.directory();
String type = FooAppProvider.class.getName();
String fileName = directory + type;
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Map<ClassLoader, Set<URL>> loadResources =
ClassLoaderResourceLoader.loadResources(fileName, Arrays.asList(contextClassLoader));
Assertions.assertTrue(loadResources.containsKey(contextClassLoader));
Assertions.assertTrue(!loadResources.get(contextClassLoader).isEmpty());
// cache
Assertions.assertNotNull(ClassLoaderResourceLoader.getClassLoaderResourcesCache());
loadResources = ClassLoaderResourceLoader.loadResources(fileName, Arrays.asList(contextClassLoader));
Assertions.assertTrue(loadResources.containsKey(contextClassLoader));
Assertions.assertTrue(!loadResources.get(contextClassLoader).isEmpty());
Assertions.assertNotNull(GlobalResourcesRepository.getGlobalReusedDisposables());
ClassLoaderResourceLoader.destroy();
Assertions.assertNull(ClassLoaderResourceLoader.getClassLoaderResourcesCache());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsInterfaceDisplayNameHasMetaCharactersTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsInterfaceDisplayNameHasMetaCharactersTest.java | /*
* 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.common.utils;
import org.apache.dubbo.common.constants.CommonConstants;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertTrue;
class NetUtilsInterfaceDisplayNameHasMetaCharactersTest {
private static final String IGNORED_DISPLAY_NAME_HAS_METACHARACTERS = "Mock(R) ^$*+[?].|-[0-9] Adapter";
private static final String SELECTED_DISPLAY_NAME = "Selected Adapter";
private static final String SELECTED_HOST_ADDR = "192.168.0.1";
@Test
void testIgnoreGivenInterfaceNameWithMetaCharacters() throws Exception {
String originIgnoredInterfaces = this.getIgnoredInterfaces();
// mock static methods of final class NetworkInterface
try (MockedStatic<NetworkInterface> mockedStaticNetif = Mockito.mockStatic(NetworkInterface.class)) {
NetworkInterface mockIgnoredNetif = Mockito.mock(NetworkInterface.class);
NetworkInterface mockSelectedNetif = Mockito.mock(NetworkInterface.class);
NetworkInterface[] mockNetifs = {mockIgnoredNetif, mockSelectedNetif};
Enumeration<NetworkInterface> mockEnumIfs = new Enumeration<NetworkInterface>() {
private int i = 0;
public NetworkInterface nextElement() {
if (mockNetifs != null && i < mockNetifs.length) {
NetworkInterface netif = mockNetifs[i++];
return netif;
} else {
throw new NoSuchElementException();
}
}
public boolean hasMoreElements() {
return (mockNetifs != null && i < mockNetifs.length);
}
};
InetAddress mockSelectedAddr = Mockito.mock(InetAddress.class);
InetAddress[] mockAddrs = {mockSelectedAddr};
Enumeration<InetAddress> mockEnumAddrs = new Enumeration<InetAddress>() {
private int i = 0;
public InetAddress nextElement() {
if (mockAddrs != null && i < mockAddrs.length) {
InetAddress addr = mockAddrs[i++];
return addr;
} else {
throw new NoSuchElementException();
}
}
public boolean hasMoreElements() {
return (mockAddrs != null && i < mockAddrs.length);
}
};
// mock static method getNetworkInterfaces
mockedStaticNetif
.when(() -> {
NetworkInterface.getNetworkInterfaces();
})
.thenReturn(mockEnumIfs);
Mockito.when(mockIgnoredNetif.isUp()).thenReturn(true);
Mockito.when(mockIgnoredNetif.getDisplayName()).thenReturn(IGNORED_DISPLAY_NAME_HAS_METACHARACTERS);
Mockito.when(mockSelectedNetif.isUp()).thenReturn(true);
Mockito.when(mockSelectedNetif.getDisplayName()).thenReturn(SELECTED_DISPLAY_NAME);
Mockito.when(mockSelectedNetif.getInetAddresses()).thenReturn(mockEnumAddrs);
Mockito.when(mockSelectedAddr.isLoopbackAddress()).thenReturn(false);
Mockito.when(mockSelectedAddr.getHostAddress()).thenReturn(SELECTED_HOST_ADDR);
Mockito.when(mockSelectedAddr.isReachable(Mockito.anyInt())).thenReturn(true);
this.setIgnoredInterfaces(IGNORED_DISPLAY_NAME_HAS_METACHARACTERS);
NetworkInterface newNetworkInterface = NetUtils.findNetworkInterface();
assertTrue(!IGNORED_DISPLAY_NAME_HAS_METACHARACTERS.equals(newNetworkInterface.getDisplayName()));
} finally {
// recover the origin ignored interfaces
this.setIgnoredInterfaces(originIgnoredInterfaces);
}
}
private String getIgnoredInterfaces() {
return SystemPropertyConfigUtils.getSystemProperty(
CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE);
}
private void setIgnoredInterfaces(String ignoredInterfaces) {
if (ignoredInterfaces != null) {
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, ignoredInterfaces);
} else {
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, "");
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/LogHelperTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/LogHelperTest.java | /*
* 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.common.utils;
import org.apache.dubbo.common.logger.Logger;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class LogHelperTest {
@Test
void testTrace() {
Logger logger = Mockito.mock(Logger.class);
when(logger.isTraceEnabled()).thenReturn(true);
LogHelper.trace(logger, "trace");
verify(logger).trace("trace");
Throwable t = new RuntimeException();
LogHelper.trace(logger, t);
verify(logger).trace(t);
LogHelper.trace(logger, "trace", t);
verify(logger).trace("trace", t);
}
@Test
void testDebug() {
Logger logger = Mockito.mock(Logger.class);
when(logger.isDebugEnabled()).thenReturn(true);
LogHelper.debug(logger, "debug");
verify(logger).debug("debug");
Throwable t = new RuntimeException();
LogHelper.debug(logger, t);
verify(logger).debug(t);
LogHelper.debug(logger, "debug", t);
verify(logger).debug("debug", t);
}
@Test
void testInfo() {
Logger logger = Mockito.mock(Logger.class);
when(logger.isInfoEnabled()).thenReturn(true);
LogHelper.info(logger, "info");
verify(logger).info("info");
Throwable t = new RuntimeException();
LogHelper.info(logger, t);
verify(logger).info(t);
LogHelper.info(logger, "info", t);
verify(logger).info("info", t);
}
@Test
void testWarn() {
Logger logger = Mockito.mock(Logger.class);
when(logger.isWarnEnabled()).thenReturn(true);
LogHelper.warn(logger, "warn");
verify(logger).warn("warn");
Throwable t = new RuntimeException();
LogHelper.warn(logger, t);
verify(logger).warn(t);
LogHelper.warn(logger, "warn", t);
verify(logger).warn("warn", t);
}
@Test
void testError() {
Logger logger = Mockito.mock(Logger.class);
when(logger.isErrorEnabled()).thenReturn(true);
LogHelper.error(logger, "error");
verify(logger).error("error");
Throwable t = new RuntimeException();
LogHelper.error(logger, t);
verify(logger).error(t);
LogHelper.error(logger, "error", t);
verify(logger).error("error", t);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/LRU2CacheTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/LRU2CacheTest.java | /*
* 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.common.utils;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class LRU2CacheTest {
@Test
void testCache() {
LRU2Cache<String, Integer> cache = new LRU2Cache<String, Integer>(3);
cache.put("one", 1);
cache.put("two", 2);
cache.put("three", 3);
assertFalse(cache.containsKey("one"));
assertFalse(cache.containsKey("two"));
assertFalse(cache.containsKey("three"));
cache.put("one", 1);
cache.put("two", 2);
cache.put("three", 3);
assertThat(cache.get("one"), equalTo(1));
assertThat(cache.get("two"), equalTo(2));
assertThat(cache.get("three"), equalTo(3));
assertThat(cache.size(), equalTo(3));
cache.put("four", 4);
cache.put("four", 4);
assertThat(cache.size(), equalTo(3));
assertFalse(cache.containsKey("one"));
assertTrue(cache.containsKey("two"));
assertTrue(cache.containsKey("three"));
assertTrue(cache.containsKey("four"));
cache.remove("four");
assertThat(cache.size(), equalTo(2));
cache.put("five", 5);
cache.put("five", 5);
assertFalse(cache.containsKey("four"));
assertTrue(cache.containsKey("five"));
assertTrue(cache.containsKey("two"));
assertTrue(cache.containsKey("three"));
assertThat(cache.size(), equalTo(3));
cache.put("six", 6);
assertFalse(cache.containsKey("six"));
}
@Test
void testCapacity() {
LRU2Cache<String, Integer> cache = new LRU2Cache<String, Integer>();
assertThat(cache.getMaxCapacity(), equalTo(1000));
cache.setMaxCapacity(10);
assertThat(cache.getMaxCapacity(), equalTo(10));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/RegexPropertiesTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/RegexPropertiesTest.java | /*
* 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.common.utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class RegexPropertiesTest {
@Test
void testGetProperty() {
RegexProperties regexProperties = new RegexProperties();
regexProperties.setProperty("org.apache.dubbo.provider.*", "http://localhost:20880");
regexProperties.setProperty("org.apache.dubbo.provider.config.*", "http://localhost:30880");
regexProperties.setProperty("org.apache.dubbo.provider.config.demo", "http://localhost:40880");
regexProperties.setProperty("org.apache.dubbo.consumer.*.demo", "http://localhost:50880");
regexProperties.setProperty("*.service", "http://localhost:60880");
Assertions.assertEquals(
"http://localhost:20880", regexProperties.getProperty("org.apache.dubbo.provider.cluster"));
Assertions.assertEquals(
"http://localhost:30880", regexProperties.getProperty("org.apache.dubbo.provider.config.cluster"));
Assertions.assertEquals(
"http://localhost:40880", regexProperties.getProperty("org.apache.dubbo.provider.config.demo"));
Assertions.assertEquals(
"http://localhost:50880", regexProperties.getProperty("org.apache.dubbo.consumer.service.demo"));
Assertions.assertEquals("http://localhost:60880", regexProperties.getProperty("org.apache.dubbo.service"));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityManagerTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityManagerTest.java | /*
* 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.common.utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class SerializeSecurityManagerTest {
@Test
void testPrefix() {
TestAllowClassNotifyListener.setCount(0);
SerializeSecurityManager ssm = new SerializeSecurityManager();
ssm.registerListener(new TestAllowClassNotifyListener());
ssm.addToAllowed("java.util.HashMap");
ssm.addToAllowed("com.example.DemoInterface");
ssm.addToAllowed("com.sun.Interface1");
ssm.addToAllowed("com.sun.Interface2");
Assertions.assertTrue(ssm.getAllowedPrefix().contains("java.util.HashMap"));
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.example.DemoInterface"));
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.sun.Interface1"));
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.sun.Interface2"));
Assertions.assertEquals(ssm.getAllowedPrefix(), TestAllowClassNotifyListener.getAllowedList());
Assertions.assertEquals(7, TestAllowClassNotifyListener.getCount());
ssm.addToDisAllowed("com.sun.Interface");
Assertions.assertFalse(ssm.getAllowedPrefix().contains("com.sun.Interface1"));
Assertions.assertFalse(ssm.getAllowedPrefix().contains("com.sun.Interface2"));
Assertions.assertEquals(ssm.getDisAllowedPrefix(), TestAllowClassNotifyListener.getDisAllowedList());
Assertions.assertEquals(9, TestAllowClassNotifyListener.getCount());
ssm.addToAllowed("com.sun.Interface3");
Assertions.assertFalse(ssm.getAllowedPrefix().contains("com.sun.Interface3"));
Assertions.assertEquals(9, TestAllowClassNotifyListener.getCount());
ssm.addToAllowed("java.util.HashMap");
Assertions.assertEquals(9, TestAllowClassNotifyListener.getCount());
ssm.addToDisAllowed("com.sun.Interface");
Assertions.assertEquals(9, TestAllowClassNotifyListener.getCount());
ssm.addToAlwaysAllowed("com.sun.Interface3");
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.sun.Interface3"));
Assertions.assertEquals(10, TestAllowClassNotifyListener.getCount());
ssm.addToAlwaysAllowed("com.sun.Interface3");
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.sun.Interface3"));
Assertions.assertEquals(10, TestAllowClassNotifyListener.getCount());
}
@Test
void testStatus1() {
SerializeSecurityManager ssm = new SerializeSecurityManager();
ssm.registerListener(new TestAllowClassNotifyListener());
Assertions.assertEquals(AllowClassNotifyListener.DEFAULT_STATUS, ssm.getCheckStatus());
Assertions.assertEquals(AllowClassNotifyListener.DEFAULT_STATUS, TestAllowClassNotifyListener.getStatus());
ssm.setCheckStatus(SerializeCheckStatus.STRICT);
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.STRICT, TestAllowClassNotifyListener.getStatus());
ssm.setCheckStatus(SerializeCheckStatus.WARN);
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.WARN, TestAllowClassNotifyListener.getStatus());
ssm.setCheckStatus(SerializeCheckStatus.STRICT);
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.WARN, TestAllowClassNotifyListener.getStatus());
ssm.setCheckStatus(SerializeCheckStatus.DISABLE);
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.DISABLE, TestAllowClassNotifyListener.getStatus());
ssm.setCheckStatus(SerializeCheckStatus.STRICT);
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.DISABLE, TestAllowClassNotifyListener.getStatus());
ssm.setCheckStatus(SerializeCheckStatus.WARN);
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.DISABLE, TestAllowClassNotifyListener.getStatus());
}
@Test
void testStatus2() {
SerializeSecurityManager ssm = new SerializeSecurityManager();
ssm.setCheckStatus(SerializeCheckStatus.STRICT);
ssm.registerListener(new TestAllowClassNotifyListener());
Assertions.assertEquals(ssm.getCheckStatus(), TestAllowClassNotifyListener.getStatus());
Assertions.assertEquals(SerializeCheckStatus.STRICT, TestAllowClassNotifyListener.getStatus());
}
@Test
void testSerializable() {
SerializeSecurityManager ssm = new SerializeSecurityManager();
ssm.registerListener(new TestAllowClassNotifyListener());
Assertions.assertTrue(ssm.isCheckSerializable());
Assertions.assertTrue(TestAllowClassNotifyListener.isCheckSerializable());
ssm.setCheckSerializable(true);
Assertions.assertTrue(ssm.isCheckSerializable());
Assertions.assertTrue(TestAllowClassNotifyListener.isCheckSerializable());
ssm.setCheckSerializable(false);
Assertions.assertFalse(ssm.isCheckSerializable());
Assertions.assertFalse(TestAllowClassNotifyListener.isCheckSerializable());
ssm.setCheckSerializable(true);
Assertions.assertFalse(ssm.isCheckSerializable());
Assertions.assertFalse(TestAllowClassNotifyListener.isCheckSerializable());
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java | dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java | /*
* 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.common.utils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.json.JsonUtil;
import org.apache.dubbo.common.json.impl.FastJson2Impl;
import org.apache.dubbo.common.json.impl.FastJsonImpl;
import org.apache.dubbo.common.json.impl.GsonImpl;
import org.apache.dubbo.common.json.impl.JacksonImpl;
import org.apache.dubbo.common.utils.json.TestEnum;
import org.apache.dubbo.common.utils.json.TestObjectA;
import org.apache.dubbo.common.utils.json.TestObjectB;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
import org.mockito.Mockito;
class JsonUtilsTest {
private AtomicBoolean allowFastjson2 = new AtomicBoolean(true);
private AtomicBoolean allowFastjson = new AtomicBoolean(true);
private AtomicBoolean allowGson = new AtomicBoolean(true);
private AtomicBoolean allowJackson = new AtomicBoolean(true);
private MockedConstruction<FastJson2Impl> fastjson2Mock;
private MockedConstruction<FastJsonImpl> fastjsonMock;
private MockedConstruction<GsonImpl> gsonMock;
private MockedConstruction<JacksonImpl> jacksonMock;
@AfterEach
void teardown() {
if (fastjsonMock != null) {
fastjsonMock.close();
}
if (fastjson2Mock != null) {
fastjson2Mock.close();
}
if (gsonMock != null) {
gsonMock.close();
}
if (jacksonMock != null) {
jacksonMock.close();
}
}
@Test
void testIsJson() {
JsonUtils.setJson(null);
// prefer use fastjson2
System.setProperty("dubbo.json-framework.prefer", "fastjson2");
Assertions.assertTrue(
JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}"));
Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string"));
Assertions.assertTrue(
JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]"));
System.clearProperty("dubbo.json-framework.prefer");
// prefer use fastjson
JsonUtils.setJson(null);
System.setProperty("dubbo.json-framework.prefer", "fastjson");
Assertions.assertTrue(
JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}"));
Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string"));
Assertions.assertTrue(
JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]"));
System.clearProperty("dubbo.json-framework.prefer");
// prefer use gson
JsonUtils.setJson(null);
System.setProperty("dubbo.json-framework.prefer", "gson");
Assertions.assertTrue(
JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}"));
Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string"));
Assertions.assertTrue(
JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]"));
System.clearProperty("dubbo.json-framework.prefer");
// prefer use jackson
JsonUtils.setJson(null);
System.setProperty("dubbo.json-framework.prefer", "jackson");
Assertions.assertTrue(
JsonUtils.getJson().isJson("{\"title\":\"Java Programming\",\"author\":\"John Doe\",\"pages\":300}"));
Assertions.assertFalse(JsonUtils.getJson().isJson("This is not a JSON string"));
Assertions.assertTrue(
JsonUtils.getJson().isJson("[{\"title\":\"Java Programming\"}, {\"title\":\"Python Programming\"}]"));
System.clearProperty("dubbo.json-framework.prefer");
}
@Test
void testGetJson1() {
Assertions.assertNotNull(JsonUtils.getJson());
Assertions.assertEquals(JsonUtils.getJson(), JsonUtils.getJson());
Map<String, String> map = new HashMap<>();
map.put("a", "a");
Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map));
Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class));
Assertions.assertEquals(
Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class));
// prefer use fastjson2
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2");
Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map));
Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class));
Assertions.assertEquals(
Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class));
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use fastjson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson");
Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map));
Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class));
Assertions.assertEquals(
Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class));
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use gson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson");
Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map));
Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class));
Assertions.assertEquals(
Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class));
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use jackson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson");
Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map));
Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class));
Assertions.assertEquals(
Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class));
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
setJson(null);
}
@Test
void consistentTest() throws Exception {
ObjectMapper om = new ObjectMapper();
List<Object> objs = new LinkedList<>();
{
objs.add(null);
}
{
Map<String, String> map = new HashMap<>();
map.put("a", "a");
objs.add(map);
}
{
TestObjectA a = new TestObjectA();
objs.add(a);
}
{
TestObjectA a = new TestObjectA();
a.setTestEnum(TestEnum.TYPE_A);
objs.add(a);
}
{
TestObjectB b = new TestObjectB();
objs.add(b);
}
{
TestObjectB b = new TestObjectB();
b.setInnerA(new TestObjectB.Inner());
b.setInnerB(new TestObjectB.Inner());
objs.add(b);
}
{
TestObjectB b = new TestObjectB();
TestObjectB.Inner inner1 = new TestObjectB.Inner();
TestObjectB.Inner inner2 = new TestObjectB.Inner();
inner1.setName("Test");
inner2.setName("Test");
b.setInnerA(inner1);
b.setInnerB(inner2);
objs.add(b);
}
{
TestObjectB b = new TestObjectB();
TestObjectB.Inner inner1 = new TestObjectB.Inner();
inner1.setName("Test");
b.setInnerA(inner1);
b.setInnerB(inner1);
objs.add(b);
}
for (Object obj : objs) {
// prefer use fastjson2
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2");
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
String fromFastjson2 = JsonUtils.getJson().toJson(obj);
SystemPropertyConfigUtils.clearSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use fastjson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson");
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
String fromFastjson1 = JsonUtils.getJson().toJson(obj);
SystemPropertyConfigUtils.clearSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use gson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson");
Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson());
String fromGson = JsonUtils.getJson().toJson(obj);
SystemPropertyConfigUtils.clearSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use jackson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson");
Assertions.assertInstanceOf(JacksonImpl.class, JsonUtils.getJson());
String fromJackson = JsonUtils.getJson().toJson(obj);
SystemPropertyConfigUtils.clearSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
setJson(null);
Assertions.assertEquals(om.readTree(fromFastjson1), om.readTree(fromFastjson2));
Assertions.assertEquals(om.readTree(fromFastjson1), om.readTree(fromGson));
Assertions.assertEquals(om.readTree(fromFastjson2), om.readTree(fromGson));
Assertions.assertEquals(om.readTree(fromFastjson1), om.readTree(fromJackson));
Assertions.assertEquals(om.readTree(fromFastjson2), om.readTree(fromJackson));
}
}
@Test
void testGetJson2() {
fastjson2Mock = Mockito.mockConstruction(FastJson2Impl.class, (mock, context) -> {
Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowFastjson2.get());
Mockito.when(mock.getName()).thenAnswer(invocation -> "fastjson2");
});
fastjsonMock = Mockito.mockConstruction(FastJsonImpl.class, (mock, context) -> {
Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowFastjson.get());
Mockito.when(mock.getName()).thenAnswer(invocation -> "fastjson");
});
gsonMock = Mockito.mockConstruction(GsonImpl.class, (mock, context) -> {
Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowGson.get());
Mockito.when(mock.getName()).thenAnswer(invocation -> "gson");
});
jacksonMock = Mockito.mockConstruction(JacksonImpl.class, (mock, context) -> {
Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowJackson.get());
Mockito.when(mock.getName()).thenAnswer(invocation -> "jackson");
});
// default use fastjson2
setJson(null);
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
// prefer use fastjson2
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2");
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
// prefer use fastjson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson");
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use gson
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson");
Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
// prefer use not found
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "notfound");
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
setJson(null);
// TCCL not found fastjson2
allowFastjson2.set(false);
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
allowFastjson2.set(true);
setJson(null);
// TCCL not found fastjson2, fastjson
allowFastjson2.set(false);
allowFastjson.set(false);
Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson());
allowFastjson.set(true);
allowFastjson2.set(true);
setJson(null);
// TCCL not found fastjson2, fastjson, gson
allowFastjson2.set(false);
allowFastjson.set(false);
allowGson.set(false);
Assertions.assertInstanceOf(JacksonImpl.class, JsonUtils.getJson());
allowGson.set(true);
allowFastjson.set(true);
allowFastjson2.set(true);
setJson(null);
// TCCL not found fastjson2, prefer use fastjson2
allowFastjson2.set(false);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2");
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
allowFastjson2.set(true);
setJson(null);
// TCCL not found fastjson, prefer use fastjson
allowFastjson.set(false);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson");
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
allowFastjson.set(true);
setJson(null);
// TCCL not found gson, prefer use gson
allowGson.set(false);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson");
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
allowGson.set(true);
setJson(null);
// TCCL not found jackson, prefer use jackson
allowJackson.set(false);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson");
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
allowJackson.set(true);
setJson(null);
// TCCL not found fastjson, gson
allowFastjson2.set(false);
allowFastjson.set(false);
allowGson.set(false);
allowJackson.set(false);
Assertions.assertThrows(IllegalStateException.class, JsonUtils::getJson);
allowGson.set(true);
allowFastjson.set(true);
allowFastjson2.set(true);
allowJackson.set(true);
setJson(null);
}
private static Field jsonFieldCache;
/**
* Test for JDK 21+ compatibility with SequencedCollection.
* Verifies that toJavaList() works correctly with Jackson on JDK 25.
* This test ensures that the fix using ArrayList.class instead of List.class
* resolves the type inference issue introduced in JDK 21+.
*
* @date 2025-11-04
*/
@Test
void testToJavaListJDKCompatibility() {
// Test with Jackson specifically, as it's most affected by SequencedCollection changes
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson");
// Test parsing JSON array of strings (the original failing case from ConfiguratorTest)
String jsonArray = "[\"override://0.0.0.0/com.xx.Service?timeout=6666\", "
+ "\"absent://0.0.0.0/com.xx.Service?timeout=8888\"]";
List<String> result = JsonUtils.toJavaList(jsonArray, String.class);
Assertions.assertNotNull(result, "Result should not be null");
Assertions.assertEquals(2, result.size(), "Should parse 2 elements");
Assertions.assertTrue(result.get(0).startsWith("override://"), "First element should start with 'override://'");
Assertions.assertTrue(result.get(1).startsWith("absent://"), "Second element should start with 'absent://'");
// Test parsing JSON array of objects
String jsonObjectArray = "[{\"a\":\"value1\"}, {\"b\":\"value2\"}]";
List<Map> mapResult = JsonUtils.toJavaList(jsonObjectArray, Map.class);
Assertions.assertNotNull(mapResult, "Map result should not be null");
Assertions.assertEquals(2, mapResult.size(), "Should parse 2 map elements");
Assertions.assertTrue(mapResult.get(0).containsKey("a"), "First map should contain key 'a'");
Assertions.assertTrue(mapResult.get(1).containsKey("b"), "Second map should contain key 'b'");
// Test with other JSON implementations to ensure consistency
String[] implementations = {"fastjson2", "fastjson", "gson"};
for (String impl : implementations) {
setJson(null);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, impl);
List<String> implResult = JsonUtils.toJavaList(jsonArray, String.class);
Assertions.assertNotNull(implResult, impl + " should parse the array");
Assertions.assertEquals(2, implResult.size(), impl + " should parse 2 elements");
SystemPropertyConfigUtils.clearSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
}
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
setJson(null);
}
private static void setJson(JsonUtil json) {
try {
if (jsonFieldCache == null) {
jsonFieldCache = JsonUtils.class.getDeclaredField("jsonUtil");
jsonFieldCache.setAccessible(true);
}
jsonFieldCache.set(null, json);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.