Fluent style builder API support(#3431) (#3549)

This commit is contained in:
Jia He 2019-03-09 20:17:30 +08:00 committed by kezhenxu94
parent 42646d7f36
commit b7ca86b81c
37 changed files with 6762 additions and 0 deletions

View File

@ -0,0 +1,69 @@
/*
* 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.config.builders;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractConfig;
import java.util.HashMap;
import java.util.Map;
/**
* AbstractBuilder
*
* @since 2.7
*/
public abstract class AbstractBuilder<T extends AbstractConfig, B extends AbstractBuilder> {
/**
* The config id
*/
protected String id;
protected String prefix;
protected B id(String id) {
this.id = id;
return getThis();
}
protected B prefix(String prefix) {
this.prefix = prefix;
return getThis();
}
protected abstract B getThis();
protected static Map<String, String> appendParameter(Map<String, String> parameters, String key, String value) {
if (parameters == null) {
parameters = new HashMap<>();
}
parameters.put(key, value);
return parameters;
}
protected static Map<String, String> appendParameters(Map<String, String> parameters, Map<String, String> appendParameters) {
if (parameters == null) {
parameters = new HashMap<>();
}
parameters.putAll(appendParameters);
return parameters;
}
protected void build(T instance) {
if (!StringUtils.isEmpty(id)) instance.setId(id);
if (!StringUtils.isEmpty(prefix)) instance.setPrefix(prefix);
}
}

View File

@ -0,0 +1,294 @@
/*
* 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.config.builders;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.rpc.Filter;
import java.util.ArrayList;
import java.util.List;
/**
* AbstractBuilder
*
* @since 2.7
*/
public abstract class AbstractInterfaceBuilder<T extends AbstractInterfaceConfig, B extends AbstractInterfaceBuilder<T, B>>
extends AbstractMethodBuilder<T, B> {
/**
* Local impl class name for the service interface
*/
protected String local;
/**
* Local stub class name for the service interface
*/
protected String stub;
/**
* Service monitor
*/
protected MonitorConfig monitor;
/**
* Strategies for generating dynamic agentsthere are two strategies can be choosed: jdk and javassist
*/
protected String proxy;
/**
* Cluster type
*/
protected String cluster;
/**
* The {@link Filter} when the provider side exposed a service or the customer side references a remote service used,
* if there are more than one, you can use commas to separate them
*/
protected String filter;
/**
* The Listener when the provider side exposes a service or the customer side references a remote service used
* if there are more than one, you can use commas to separate them
*/
protected String listener;
/**
* The owner of the service providers
*/
protected String owner;
/**
* Connection limits, 0 means shared connection, otherwise it defines the connections delegated to the current service
*/
protected Integer connections;
/**
* The layer of service providers
*/
protected String layer;
/**
* The application info
*/
protected ApplicationConfig application;
/**
* The module info
*/
protected ModuleConfig module;
/**
* Registry centers
*/
protected List<RegistryConfig> registries;
protected String registryIds;
// connection events
protected String onconnect;
/**
* Disconnection events
*/
protected String ondisconnect;
protected MetadataReportConfig metadataReportConfig;
protected ConfigCenterConfig configCenter;
// callback limits
private Integer callbacks;
// the scope for referring/exporting a service, if it's local, it means searching in current JVM only.
private String scope;
/**
* @param local
* @see org.apache.dubbo.config.builders.AbstractInterfaceBuilder#stub(String)
* @deprecated Replace to <code>stub(String)</code>
*/
@Deprecated
public B local(String local) {
this.local = local;
return getThis();
}
/**
* @param local
* @see org.apache.dubbo.config.builders.AbstractInterfaceBuilder#stub(Boolean)
* @deprecated Replace to <code>stub(Boolean)</code>
*/
@Deprecated
public B local(Boolean local) {
if (local != null) {
this.local = local.toString();
} else {
this.local = null;
}
return getThis();
}
public B stub(String stub) {
this.stub = stub;
return getThis();
}
public B stub(Boolean stub) {
if (stub != null) {
this.stub = stub.toString();
} else {
this.stub = null;
}
return getThis();
}
public B monitor(MonitorConfig monitor) {
this.monitor = monitor;
return getThis();
}
public B monitor(String monitor) {
this.monitor = new MonitorConfig(monitor);
return getThis();
}
public B proxy(String proxy) {
this.proxy = proxy;
return getThis();
}
public B cluster(String cluster) {
this.cluster = cluster;
return getThis();
}
public B filter(String filter) {
this.filter = filter;
return getThis();
}
public B listener(String listener) {
this.listener = listener;
return getThis();
}
public B owner(String owner) {
this.owner = owner;
return getThis();
}
public B connections(Integer connections) {
this.connections = connections;
return getThis();
}
public B layer(String layer) {
this.layer = layer;
return getThis();
}
public B application(ApplicationConfig application) {
this.application = application;
return getThis();
}
public B module(ModuleConfig module) {
this.module = module;
return getThis();
}
public B addRegistries(List<RegistryConfig> registries) {
if (this.registries == null) {
this.registries = new ArrayList<>();
}
this.registries.addAll(registries);
return getThis();
}
public B addRegistry(RegistryConfig registry) {
if (this.registries == null) {
this.registries = new ArrayList<>();
}
this.registries.add(registry);
return getThis();
}
public B registryIds(String registryIds) {
this.registryIds = registryIds;
return getThis();
}
public B onconnect(String onconnect) {
this.onconnect = onconnect;
return getThis();
}
public B ondisconnect(String ondisconnect) {
this.ondisconnect = ondisconnect;
return getThis();
}
public B metadataReportConfig(MetadataReportConfig metadataReportConfig) {
this.metadataReportConfig = metadataReportConfig;
return getThis();
}
public B configCenter(ConfigCenterConfig configCenter) {
this.configCenter = configCenter;
return getThis();
}
public B callbacks(Integer callbacks) {
this.callbacks = callbacks;
return getThis();
}
public B scope(String scope) {
this.scope = scope;
return getThis();
}
public void build(T instance) {
super.build(instance);
if (!StringUtils.isEmpty(local)) instance.setLocal(local);
if (!StringUtils.isEmpty(stub)) instance.setStub(stub);
if (monitor != null) instance.setMonitor(monitor);
if (!StringUtils.isEmpty(proxy)) instance.setProxy(proxy);
if (!StringUtils.isEmpty(cluster)) instance.setCluster(cluster);
if (!StringUtils.isEmpty(filter)) instance.setFilter(filter);
if (!StringUtils.isEmpty(listener)) instance.setListener(listener);
if (!StringUtils.isEmpty(owner)) instance.setOwner(owner);
if (connections != null) instance.setConnections(connections);
if (!StringUtils.isEmpty(layer)) instance.setLayer(layer);
if (application != null) instance.setApplication(application);
if (module != null) instance.setModule(module);
if (registries != null) instance.setRegistries(registries);
if (!StringUtils.isEmpty(registryIds)) instance.setRegistryIds(registryIds);
if (!StringUtils.isEmpty(onconnect)) instance.setOnconnect(onconnect);
if (!StringUtils.isEmpty(ondisconnect)) instance.setOndisconnect(ondisconnect);
if (metadataReportConfig != null) instance.setMetadataReportConfig(metadataReportConfig);
if (configCenter != null) instance.setConfigCenter(configCenter);
if (callbacks != null) instance.setCallbacks(callbacks);
if (!StringUtils.isEmpty(scope)) instance.setScope(scope);
}
}

View File

@ -0,0 +1,188 @@
/*
* 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.config.builders;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractMethodConfig;
import java.util.Map;
/**
* AbstractBuilder
*
* @since 2.7
*/
public abstract class AbstractMethodBuilder<T extends AbstractMethodConfig, B extends AbstractMethodBuilder<T, B>>
extends AbstractBuilder<T, B>{
/**
* The timeout for remote invocation in milliseconds
*/
protected Integer timeout;
/**
* The retry times
*/
protected Integer retries;
/**
* max concurrent invocations
*/
protected Integer actives;
/**
* The load balance
*/
protected String loadbalance;
/**
* Whether to async
* note that: it is an unreliable asynchronism that ignores return values and does not block threads.
*/
protected Boolean async;
/**
* Whether to ack async-sent
*/
protected Boolean sent;
/**
* The name of mock class which gets called when a service fails to execute
*
* note that: the mock doesn't support on the provider sideand the mock is executed when a non-business exception
* occurs after a remote service call
*/
protected String mock;
/**
* Merger
*/
protected String merger;
/**
* Cache the return result with the call parameter as key, the following options are available: lru, threadlocal,
* jcache, etc.
*/
protected String cache;
/**
* Whether JSR303 standard annotation validation is enabled or not, if enabled, annotations on method parameters will
* be validated
*/
protected String validation;
/**
* The customized parameters
*/
protected Map<String, String> parameters;
/**
* Forks for forking cluster
*/
protected Integer forks;
public B timeout(Integer timeout) {
this.timeout = timeout;
return getThis();
}
public B retries(Integer retries) {
this.retries = retries;
return getThis();
}
public B actives(Integer actives) {
this.actives = actives;
return getThis();
}
public B loadbalance(String loadbalance) {
this.loadbalance = loadbalance;
return getThis();
}
public B async(Boolean async) {
this.async = async;
return getThis();
}
public B sent(Boolean sent) {
this.sent = sent;
return getThis();
}
public B mock(String mock) {
this.mock = mock;
return getThis();
}
public B mock(Boolean mock) {
if (mock != null) {
this.mock = mock.toString();
} else {
this.mock = null;
}
return getThis();
}
public B merger(String merger) {
this.merger = merger;
return getThis();
}
public B cache(String cache) {
this.cache = cache;
return getThis();
}
public B validation(String validation) {
this.validation = validation;
return getThis();
}
public B appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(parameters, appendParameters);
return getThis();
}
public B appendParameter(String key, String value) {
this.parameters = appendParameter(parameters, key, value);
return getThis();
}
public B forks(Integer forks) {
this.forks = forks;
return getThis();
}
@SuppressWarnings("unchecked")
public void build(T instance) {
super.build(instance);
if (actives != null) instance.setActives(actives);
if (async != null) instance.setAsync(async);
if (!StringUtils.isEmpty(cache)) instance.setCache(cache);
if (forks != null) instance.setForks(forks);
if (!StringUtils.isEmpty(loadbalance)) instance.setLoadbalance(loadbalance);
if (!StringUtils.isEmpty(merger)) instance.setMerger(merger);
if(!StringUtils.isEmpty(mock)) instance.setMock(mock);
if (retries != null) instance.setRetries(retries);
if (sent != null) instance.setSent(sent);
if (timeout != null) instance.setTimeout(timeout);
if (!StringUtils.isEmpty(validation)) instance.setValidation(validation);
if (parameters != null) instance.setParameters(parameters);
}
}

View File

@ -0,0 +1,142 @@
/*
* 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.config.builders;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractReferenceConfig;
/**
* AbstractBuilder
*
* @since 2.7
*/
public abstract class AbstractReferenceBuilder<T extends AbstractReferenceConfig, B extends AbstractReferenceBuilder<T, B>>
extends AbstractInterfaceBuilder<T, B> {
/**
* Check if service provider exists, if not exists, it will be fast fail
*/
protected Boolean check;
/**
* Whether to eagle-init
*/
protected Boolean init;
/**
* Whether to use generic interface
*/
protected String generic;
/**
* Whether to find reference's instance from the current JVM
*/
protected Boolean injvm;
/**
* Lazy create connection
*/
protected Boolean lazy;
protected String reconnect;
protected Boolean sticky;
/**
* The remote service version the customer side will reference
*/
protected String version;
/**
* The remote service group the customer side will reference
*/
protected String group;
public B check(Boolean check) {
this.check = check;
return getThis();
}
public B init(Boolean init) {
this.init = init;
return getThis();
}
public B generic(String generic) {
this.generic = generic;
return getThis();
}
public B generic(Boolean generic) {
if (generic != null) {
this.generic = generic.toString();
} else {
this.generic = null;
}
return getThis();
}
/**
* @param injvm
* @see org.apache.dubbo.config.builders.AbstractInterfaceBuilder#scope(String)
* @deprecated instead, use the parameter <b>scope</b> to judge if it's in jvm, scope=local
*/
@Deprecated
public B injvm(Boolean injvm) {
this.injvm = injvm;
return getThis();
}
public B lazy(Boolean lazy) {
this.lazy = lazy;
return getThis();
}
public B reconnect(String reconnect) {
this.reconnect = reconnect;
return getThis();
}
public B sticky(Boolean sticky) {
this.sticky = sticky;
return getThis();
}
public B version(String version) {
this.version = version;
return getThis();
}
public B group(String group) {
this.group = group;
return getThis();
}
public void build(T instance) {
super.build(instance);
if (check != null) instance.setCheck(check);
if (init != null) instance.setInit(init);
if (!StringUtils.isEmpty(generic)) instance.setGeneric(generic);
if (injvm != null) instance.setInjvm(injvm);
if (lazy != null) instance.setLazy(lazy);
if (!StringUtils.isEmpty(reconnect)) instance.setReconnect(reconnect);
if (sticky != null) instance.setSticky(sticky);
if (!StringUtils.isEmpty(version)) instance.setVersion(version);
if (!StringUtils.isEmpty(group)) instance.setGroup(group);
}
}

View File

@ -0,0 +1,246 @@
/*
* 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.config.builders;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractServiceConfig;
import org.apache.dubbo.config.ProtocolConfig;
import java.util.ArrayList;
import java.util.List;
/**
* AbstractBuilder
*
* @since 2.7
*/
public abstract class AbstractServiceBuilder<T extends AbstractServiceConfig, B extends AbstractServiceBuilder<T, B>>
extends AbstractInterfaceBuilder<T, B> {
/**
* The service version
*/
protected String version;
/**
* The service group
*/
protected String group;
/**
* whether the service is deprecated
*/
protected Boolean deprecated;
/**
* The time delay register service (milliseconds)
*/
protected Integer delay;
/**
* Whether to export the service
*/
protected Boolean export;
/**
* The service weight
*/
protected Integer weight;
/**
* Document center
*/
protected String document;
/**
* Whether to register as a dynamic service or not on register center, it the value is false, the status will be disabled
* after the service registered,and it needs to be enabled manually; if you want to disable the service, you also need
* manual processing
*/
protected Boolean dynamic;
/**
* Whether to use token
*/
protected String token;
/**
* Whether to export access logs to logs
*/
protected String accesslog;
/**
* The protocol list the service will export with
*/
protected List<ProtocolConfig> protocols;
protected String protocolIds;
// provider tag
protected String tag;
// max allowed execute times
private Integer executes;
/**
* Whether to register
*/
private Boolean register;
/**
* Warm up period
*/
private Integer warmup;
/**
* The serialization type
*/
private String serialization;
public B version(String version) {
this.version = version;
return getThis();
}
public B group(String group) {
this.group = group;
return getThis();
}
public B deprecated(Boolean deprecated) {
this.deprecated = deprecated;
return getThis();
}
public B delay(Integer delay) {
this.delay = delay;
return getThis();
}
public B export(Boolean export) {
this.export = export;
return getThis();
}
public B weight(Integer weight) {
this.weight = weight;
return getThis();
}
public B document(String document) {
this.document = document;
return getThis();
}
public B dynamic(Boolean dynamic) {
this.dynamic = dynamic;
return getThis();
}
public B token(String token) {
this.token = token;
return getThis();
}
public B token(Boolean token) {
if (token != null) {
this.token = token.toString();
} else {
this.token = null;
}
return getThis();
}
public B accesslog(String accesslog) {
this.accesslog = accesslog;
return getThis();
}
public B accesslog(Boolean accesslog) {
if (accesslog != null) {
this.accesslog = accesslog.toString();
} else {
this.accesslog = null;
}
return getThis();
}
public B addProtocols(List<ProtocolConfig> protocols) {
if (this.protocols == null) {
this.protocols = new ArrayList<>();
}
this.protocols.addAll(protocols);
return getThis();
}
public B addProtocol(ProtocolConfig protocol) {
if (this.protocols == null) {
this.protocols = new ArrayList<>();
}
this.protocols.add(protocol);
return getThis();
}
public B protocolIds(String protocolIds) {
this.protocolIds = protocolIds;
return getThis();
}
public B tag(String tag) {
this.tag = tag;
return getThis();
}
public B executes(Integer executes) {
this.executes = executes;
return getThis();
}
public B register(Boolean register) {
this.register = register;
return getThis();
}
public B warmup(Integer warmup) {
this.warmup = warmup;
return getThis();
}
public B serialization(String serialization) {
this.serialization = serialization;
return getThis();
}
public void build(T instance) {
super.build(instance);
if (!StringUtils.isEmpty(version)) instance.setVersion(version);
if (!StringUtils.isEmpty(group)) instance.setGroup(group);
if (deprecated != null) instance.setDeprecated(deprecated);
if (delay != null) instance.setDelay(delay);
if (export != null) instance.setExport(export);
if (weight != null) instance.setWeight(weight);
if (!StringUtils.isEmpty(document)) instance.setDocument(document);
if (dynamic != null) instance.setDynamic(dynamic);
if (!StringUtils.isEmpty(token)) instance.setToken(token);
if (!StringUtils.isEmpty(accesslog)) instance.setAccesslog(accesslog);
if (protocols != null) instance.setProtocols(protocols);
if (!StringUtils.isEmpty(protocolIds)) instance.setProtocolIds(protocolIds);
if (tag != null) instance.setTag(tag);
if (executes != null) instance.setExecutes(executes);
if (register != null) instance.setRegister(register);
if (warmup != null) instance.setWarmup(warmup);
if (!StringUtils.isEmpty(serialization)) instance.setSerialization(serialization);
}
}

View File

@ -0,0 +1,193 @@
/*
* 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.config.builders;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
/**
* This is a builder for build {@link ApplicationConfig}.
* @since 2.7
*/
public class ApplicationBuilder extends AbstractBuilder<ApplicationConfig, ApplicationBuilder> {
private String name;
private String version;
private String owner;
private String organization;
private String architecture;
private String environment = Constants.PRODUCTION_ENVIRONMENT;
private String compiler;
private String logger;
private List<RegistryConfig> registries;
private String registryIds;
private MonitorConfig monitor;
private Boolean isDefault;
private String dumpDirectory;
private Boolean qosEnable;
private Integer qosPort;
private Boolean qosAcceptForeignIp;
private Map<String, String> parameters;
private String shutwait;
public ApplicationBuilder name(String name) {
this.name = name;
return getThis();
}
public ApplicationBuilder version(String version) {
this.version = version;
return getThis();
}
public ApplicationBuilder owner(String owner) {
this.owner = owner;
return getThis();
}
public ApplicationBuilder organization(String organization) {
this.organization = organization;
return getThis();
}
public ApplicationBuilder architecture(String architecture) {
this.architecture = architecture;
return getThis();
}
public ApplicationBuilder environment(String environment) {
this.environment = environment;
return getThis();
}
public ApplicationBuilder compiler(String compiler) {
this.compiler = compiler;
return getThis();
}
public ApplicationBuilder logger(String logger) {
this.logger = logger;
return getThis();
}
public ApplicationBuilder addRegistry(RegistryConfig registry) {
if (this.registries == null) {
this.registries = new ArrayList<>();
}
this.registries.add(registry);
return getThis();
}
public ApplicationBuilder addRegistries(List<? extends RegistryConfig> registries) {
if (this.registries == null) {
this.registries = new ArrayList<>();
}
this.registries.addAll(registries);
return getThis();
}
public ApplicationBuilder registryIds(String registryIds) {
this.registryIds = registryIds;
return getThis();
}
public ApplicationBuilder monitor(MonitorConfig monitor) {
this.monitor = monitor;
return getThis();
}
public ApplicationBuilder monitor(String monitor) {
this.monitor = new MonitorConfig(monitor);
return getThis();
}
public ApplicationBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public ApplicationBuilder dumpDirectory(String dumpDirectory) {
this.dumpDirectory = dumpDirectory;
return getThis();
}
public ApplicationBuilder qosEnable(Boolean qosEnable) {
this.qosEnable = qosEnable;
return getThis();
}
public ApplicationBuilder qosPort(Integer qosPort) {
this.qosPort = qosPort;
return getThis();
}
public ApplicationBuilder qosAcceptForeignIp(Boolean qosAcceptForeignIp) {
this.qosAcceptForeignIp = qosAcceptForeignIp;
return getThis();
}
public ApplicationBuilder shutwait(String shutwait) {
this.shutwait = shutwait;
return getThis();
}
public ApplicationBuilder appendParameter(String key, String value) {
this.parameters = appendParameter(parameters, key, value);
return getThis();
}
public ApplicationBuilder appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(parameters, appendParameters);
return getThis();
}
public ApplicationConfig build() {
ApplicationConfig config = new ApplicationConfig();
super.build(config);
config.setName(name);
config.setVersion(this.version);
config.setOwner(this.owner);
config.setOrganization(this.organization);
config.setArchitecture(this.architecture);
config.setEnvironment(this.environment);
config.setCompiler(this.compiler);
config.setLogger(this.logger);
config.setRegistries(this.registries);
config.setRegistryIds(this.registryIds);
config.setMonitor(this.monitor);
config.setDefault(this.isDefault);
config.setDumpDirectory(this.dumpDirectory);
config.setQosEnable(this.qosEnable);
config.setQosPort(this.qosPort);
config.setQosAcceptForeignIp(this.qosAcceptForeignIp);
config.setParameters(this.parameters);
if (!StringUtils.isEmpty(shutwait)) config.setShutwait(shutwait);
return config;
}
@Override
protected ApplicationBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.builders;
import org.apache.dubbo.config.ArgumentConfig;
/**
* This is a builder for build {@link ArgumentConfig}.
* @since 2.7
*/
public class ArgumentBuilder {
/**
* The argument index: index -1 represents not set
*/
private Integer index = -1;
/**
* Argument type
*/
private String type;
/**
* Whether the argument is the callback interface
*/
private Boolean callback;
public ArgumentBuilder index(Integer index) {
this.index = index;
return this;
}
public ArgumentBuilder type(String type) {
this.type = type;
return this;
}
public ArgumentBuilder callback(Boolean callback) {
this.callback = callback;
return this;
}
public ArgumentConfig build() {
ArgumentConfig argumentConfig = new ArgumentConfig();
argumentConfig.setIndex(index);
argumentConfig.setType(type);
argumentConfig.setCallback(callback);
return argumentConfig;
}
}

View File

@ -0,0 +1,148 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ConfigCenterConfig;
import java.util.Map;
/**
* This is a builder for build {@link ConfigCenterConfig}.
*
* @since 2.7
*/
public class ConfigCenterBuilder extends AbstractBuilder<ConfigCenterConfig, ConfigCenterBuilder> {
private String protocol;
private String address;
private String cluster;
private String namespace = "dubbo";
private String group = "dubbo";
private String username;
private String password;
private Long timeout = 3000L;
private Boolean highestPriority = true;
private Boolean check = true;
private String appName;
private String configFile = "dubbo.properties";
private String appConfigFile;
private Map<String, String> parameters;
public ConfigCenterBuilder protocol(String protocol) {
this.protocol = protocol;
return getThis();
}
public ConfigCenterBuilder address(String address) {
this.address = address;
return getThis();
}
public ConfigCenterBuilder cluster(String cluster) {
this.cluster = cluster;
return getThis();
}
public ConfigCenterBuilder namespace(String namespace) {
this.namespace = namespace;
return getThis();
}
public ConfigCenterBuilder group(String group) {
this.group = group;
return getThis();
}
public ConfigCenterBuilder username(String username) {
this.username = username;
return getThis();
}
public ConfigCenterBuilder password(String password) {
this.password = password;
return getThis();
}
public ConfigCenterBuilder timeout(Long timeout) {
this.timeout = timeout;
return getThis();
}
public ConfigCenterBuilder highestPriority(Boolean highestPriority) {
this.highestPriority = highestPriority;
return getThis();
}
public ConfigCenterBuilder check(Boolean check) {
this.check = check;
return getThis();
}
public ConfigCenterBuilder appName(String appName) {
this.appName = appName;
return getThis();
}
public ConfigCenterBuilder configFile(String configFile) {
this.configFile = configFile;
return getThis();
}
public ConfigCenterBuilder appConfigFile(String appConfigFile) {
this.appConfigFile = appConfigFile;
return getThis();
}
public ConfigCenterBuilder appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(this.parameters, appendParameters);
return getThis();
}
public ConfigCenterBuilder appendParameter(String key, String value) {
this.parameters = appendParameter(this.parameters, key, value);
return getThis();
}
public ConfigCenterConfig build() {
ConfigCenterConfig configCenter = new ConfigCenterConfig();
super.build(configCenter);
configCenter.setProtocol(protocol);
configCenter.setAddress(address);
configCenter.setCluster(cluster);
configCenter.setNamespace(namespace);
configCenter.setGroup(group);
configCenter.setUsername(username);
configCenter.setPassword(password);
configCenter.setTimeout(timeout);
configCenter.setHighestPriority(highestPriority);
configCenter.setCheck(check);
configCenter.setAppName(appName);
configCenter.setConfigFile(configFile);
configCenter.setAppConfigFile(appConfigFile);
configCenter.setParameters(parameters);
return configCenter;
}
@Override
protected ConfigCenterBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,118 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ConsumerConfig;
/**
* This is a builder for build {@link ConsumerConfig}.
*
* @since 2.7
*/
public class ConsumerBuilder extends AbstractReferenceBuilder<ConsumerConfig, ConsumerBuilder> {
/**
* Whether to use the default protocol
*/
private Boolean isDefault;
/**
* Networking framework client uses: netty, mina, etc.
*/
private String client;
/**
* Consumer thread pool type: cached, fixed, limit, eager
*/
private String threadpool;
/**
* Consumer threadpool core thread size
*/
private Integer corethreads;
/**
* Consumer threadpool thread size
*/
private Integer threads;
/**
* Consumer threadpool queue size
*/
private Integer queues;
/**
* By default, a TCP long-connection communication is shared between the consumer process and the provider process.
* This property can be set to share multiple TCP long-connection communications. Note that only the dubbo protocol takes effect.
*/
private Integer shareconnections;
public ConsumerBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public ConsumerBuilder client(String client) {
this.client = client;
return getThis();
}
public ConsumerBuilder threadPool(String threadPool) {
this.threadpool = threadPool;
return getThis();
}
public ConsumerBuilder coreThreads(Integer coreThreads) {
this.corethreads = coreThreads;
return getThis();
}
public ConsumerBuilder threads(Integer threads) {
this.threads = threads;
return getThis();
}
public ConsumerBuilder queues(Integer queues) {
this.queues = queues;
return getThis();
}
public ConsumerBuilder shareConnections(Integer shareConnections) {
this.shareconnections = shareConnections;
return getThis();
}
public ConsumerConfig build() {
ConsumerConfig consumer = new ConsumerConfig();
super.build(consumer);
consumer.setDefault(isDefault);
consumer.setClient(client);
consumer.setThreadpool(threadpool);
consumer.setCorethreads(corethreads);
consumer.setThreads(threads);
consumer.setQueues(queues);
consumer.setShareconnections(shareconnections);
return consumer;
}
@Override
protected ConsumerBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.config.builders;
/**
* The tools for creat builder
*
* @since 2.7
*/
public class DubboBuilders {
public static <T> ServiceBuilder<T> serviceBuilder() {
return new ServiceBuilder<>();
}
public static ApplicationBuilder applicationBuilder() {
return new ApplicationBuilder();
}
public static ConfigCenterBuilder configCenterBuilder() {
return new ConfigCenterBuilder();
}
public static ConsumerBuilder consumerBuilder() {
return new ConsumerBuilder();
}
public static MetadataReportBuilder metadataReportBuilder() {
return new MetadataReportBuilder();
}
public static MethodBuilder methodBuilder() {
return new MethodBuilder();
}
public static MonitorBuilder monitorBuilder() {
return new MonitorBuilder();
}
public static ProviderBuilder providerBuilder() {
return new ProviderBuilder();
}
public static ProtocolBuilder protocolBuilder() {
return new ProtocolBuilder();
}
public static <T> ReferenceBuilder<T> referenceBuilder() {
return new ReferenceBuilder<T>();
}
public static RegistryBuilder registryBuilder() {
return new RegistryBuilder();
}
public static ArgumentBuilder argumentBuilder() {
return new ArgumentBuilder();
}
}

View File

@ -0,0 +1,140 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.MetadataReportConfig;
import java.util.Map;
/**
* This is a builder for build {@link MetadataReportConfig}.
*
* @since 2.7
*/
public class MetadataReportBuilder extends AbstractBuilder<MetadataReportConfig, MetadataReportBuilder> {
// Register center address
private String address;
// Username to login register center
private String username;
// Password to login register center
private String password;
// Request timeout in milliseconds for register center
private Integer timeout;
/**
* The group the metadata in . It is the same as registry
*/
private String group;
// Customized parameters
private Map<String, String> parameters;
private Integer retryTimes;
private Integer retryPeriod;
/**
* By default the metadatastore will store full metadata repeatly every day .
*/
private Boolean cycleReport;
/**
* Sync report, default async
*/
private Boolean syncReport;
public MetadataReportBuilder address(String address) {
this.address = address;
return getThis();
}
public MetadataReportBuilder username(String username) {
this.username = username;
return getThis();
}
public MetadataReportBuilder password(String password) {
this.password = password;
return getThis();
}
public MetadataReportBuilder timeout(Integer timeout) {
this.timeout = timeout;
return getThis();
}
public MetadataReportBuilder group(String group) {
this.group = group;
return getThis();
}
public MetadataReportBuilder appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(this.parameters, appendParameters);
return getThis();
}
public MetadataReportBuilder appendParameter(String key, String value) {
this.parameters = appendParameter(this.parameters, key, value);
return getThis();
}
public MetadataReportBuilder retryTimes(Integer retryTimes) {
this.retryTimes = retryTimes;
return getThis();
}
public MetadataReportBuilder retryPeriod(Integer retryPeriod) {
this.retryPeriod = retryPeriod;
return getThis();
}
public MetadataReportBuilder cycleReport(Boolean cycleReport) {
this.cycleReport = cycleReport;
return getThis();
}
public MetadataReportBuilder syncReport(Boolean syncReport) {
this.syncReport = syncReport;
return getThis();
}
public MetadataReportConfig build() {
MetadataReportConfig metadataReport = new MetadataReportConfig();
super.build(metadataReport);
metadataReport.setAddress(address);
metadataReport.setUsername(username);
metadataReport.setPassword(password);
metadataReport.setTimeout(timeout);
metadataReport.setGroup(group);
metadataReport.setParameters(parameters);
metadataReport.setRetryTimes(retryTimes);
metadataReport.setRetryPeriod(retryPeriod);
metadataReport.setCycleReport(cycleReport);
metadataReport.setSyncReport(syncReport);
return metadataReport;
}
@Override
protected MetadataReportBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,237 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ArgumentConfig;
import org.apache.dubbo.config.MethodConfig;
import java.util.ArrayList;
import java.util.List;
/**
* This is a builder for build {@link MethodConfig}.
*
* @since 2.7
*/
public class MethodBuilder extends AbstractMethodBuilder<MethodConfig, MethodBuilder> {
/**
* The method name
*/
private String name;
/**
* Stat
*/
private Integer stat;
/**
* Whether to retry
*/
private Boolean retry;
/**
* If it's reliable
*/
private Boolean reliable;
/**
* Thread limits for method invocations
*/
private Integer executes;
/**
* If it's deprecated
*/
private Boolean deprecated;
/**
* Whether to enable sticky
*/
private Boolean sticky;
/**
* Whether need to return
*/
private Boolean isReturn;
/**
* Callback instance when async-call is invoked
*/
private Object oninvoke;
/**
* Callback method when async-call is invoked
*/
private String oninvokeMethod;
/**
* Callback instance when async-call is returned
*/
private Object onreturn;
/**
* Callback method when async-call is returned
*/
private String onreturnMethod;
/**
* Callback instance when async-call has exception thrown
*/
private Object onthrow;
/**
* Callback method when async-call has exception thrown
*/
private String onthrowMethod;
/**
* The method arguments
*/
private List<ArgumentConfig> arguments;
/**
* These properties come from MethodConfig's parent Config module, they will neither be collected directly from xml or API nor be delivered to url
*/
private String service;
private String serviceId;
public MethodBuilder name(String name) {
this.name = name;
return getThis();
}
public MethodBuilder stat(Integer stat) {
this.stat = stat;
return getThis();
}
public MethodBuilder retry(Boolean retry) {
this.retry = retry;
return getThis();
}
public MethodBuilder reliable(Boolean reliable) {
this.reliable = reliable;
return getThis();
}
public MethodBuilder executes(Integer executes) {
this.executes = executes;
return getThis();
}
public MethodBuilder deprecated(Boolean deprecated) {
this.deprecated = deprecated;
return getThis();
}
public MethodBuilder sticky(Boolean sticky) {
this.sticky = sticky;
return getThis();
}
public MethodBuilder isReturn(Boolean isReturn) {
this.isReturn = isReturn;
return getThis();
}
public MethodBuilder oninvoke(Object oninvoke) {
this.oninvoke = oninvoke;
return getThis();
}
public MethodBuilder oninvokeMethod(String oninvokeMethod) {
this.oninvokeMethod = oninvokeMethod;
return getThis();
}
public MethodBuilder onreturn(Object onreturn) {
this.onreturn = onreturn;
return getThis();
}
public MethodBuilder onreturnMethod(String onreturnMethod) {
this.onreturnMethod = onreturnMethod;
return getThis();
}
public MethodBuilder onthrow(Object onthrow) {
this.onthrow = onthrow;
return getThis();
}
public MethodBuilder onthrowMethod(String onthrowMethod) {
this.onthrowMethod = onthrowMethod;
return getThis();
}
public MethodBuilder addArguments(List<? extends ArgumentConfig> arguments) {
if (this.arguments == null) {
this.arguments = new ArrayList<>();
}
this.arguments.addAll(arguments);
return getThis();
}
public MethodBuilder addArgument(ArgumentConfig argument) {
if (this.arguments == null) {
this.arguments = new ArrayList<>();
}
this.arguments.add(argument);
return getThis();
}
public MethodBuilder service(String service) {
this.service = service;
return getThis();
}
public MethodBuilder serviceId(String serviceId) {
this.serviceId = serviceId;
return getThis();
}
public MethodConfig build() {
MethodConfig methodConfig = new MethodConfig();
super.build(methodConfig);
methodConfig.setArguments(arguments);
methodConfig.setDeprecated(deprecated);
methodConfig.setExecutes(executes);
methodConfig.setName(name);
methodConfig.setOninvoke(oninvoke);
methodConfig.setOninvokeMethod(oninvokeMethod);
methodConfig.setOnreturn(onreturn);
methodConfig.setOnreturnMethod(onreturnMethod);
methodConfig.setOnthrow(onthrow);
methodConfig.setOnthrowMethod(onthrowMethod);
methodConfig.setReturn(isReturn);
methodConfig.setService(service);
methodConfig.setServiceId(serviceId);
methodConfig.setSticky(sticky);
methodConfig.setReliable(reliable);
methodConfig.setStat(stat);
methodConfig.setRetry(retry);
return methodConfig;
}
@Override
protected MethodBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,132 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import java.util.ArrayList;
import java.util.List;
/**
* This is a builder for build {@link ModuleConfig}.
*
* @since 2.7
*/
public class ModuleBuilder extends AbstractBuilder<ModuleConfig, ModuleBuilder> {
/**
* Module name
*/
private String name;
/**
* Module version
*/
private String version;
/**
* Module owner
*/
private String owner;
/**
* Module's organization
*/
private String organization;
/**
* Registry centers
*/
private List<RegistryConfig> registries;
/**
* Monitor center
*/
private MonitorConfig monitor;
/**
* If it's default
*/
private Boolean isDefault;
public ModuleBuilder name(String name) {
this.name = name;
return getThis();
}
public ModuleBuilder version(String version) {
this.version = version;
return getThis();
}
public ModuleBuilder owner(String owner) {
this.owner = owner;
return getThis();
}
public ModuleBuilder organization(String organization) {
this.organization = organization;
return getThis();
}
public ModuleBuilder addRegistries(List<? extends RegistryConfig> registries) {
if (this.registries == null) {
this.registries = new ArrayList<>();
}
this.registries.addAll(registries);
return getThis();
}
public ModuleBuilder addRegistry(RegistryConfig registry) {
if (this.registries == null) {
this.registries = new ArrayList<>();
}
this.registries.add(registry);
return getThis();
}
public ModuleBuilder monitor(MonitorConfig monitor) {
this.monitor = monitor;
return getThis();
}
public ModuleBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public ModuleConfig build() {
ModuleConfig moduleConfig = new ModuleConfig();
super.build(moduleConfig);
moduleConfig.setDefault(isDefault);
moduleConfig.setMonitor(monitor);
moduleConfig.setName(name);
moduleConfig.setOrganization(organization);
moduleConfig.setOwner(owner);
moduleConfig.setRegistries(registries);
moduleConfig.setVersion(version);
return moduleConfig;
}
@Override
protected ModuleBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,137 @@
/*
* 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.config.builders;
import java.util.Map;
import org.apache.dubbo.config.MonitorConfig;
/**
* This is a builder for build {@link MonitorConfig}.
*
* @since 2.7
*/
public class MonitorBuilder extends AbstractBuilder<MonitorConfig, MonitorBuilder> {
/**
* The protocol of the monitor, if the value is registry, it will search the monitor address from the registry center,
* otherwise, it will directly connect to the monitor center
*/
private String protocol;
/**
* The monitor address
*/
private String address;
/**
* The monitor user name
*/
private String username;
/**
* The password
*/
private String password;
private String group;
private String version;
private String interval;
/**
* customized parameters
*/
private Map<String, String> parameters;
/**
* If it's default
*/
private Boolean isDefault;
public MonitorBuilder protocol(String protocol) {
this.protocol = protocol;
return getThis();
}
public MonitorBuilder address(String address) {
this.address = address;
return getThis();
}
public MonitorBuilder username(String username) {
this.username = username;
return getThis();
}
public MonitorBuilder password(String password) {
this.password = password;
return getThis();
}
public MonitorBuilder group(String group) {
this.group = group;
return getThis();
}
public MonitorBuilder version(String version) {
this.version = version;
return getThis();
}
public MonitorBuilder interval(String interval) {
this.interval = interval;
return getThis();
}
public MonitorBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public MonitorBuilder appendParameter(String key, String value) {
this.parameters = appendParameter(parameters, key, value);
return getThis();
}
public MonitorBuilder appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(parameters, appendParameters);
return getThis();
}
public MonitorConfig build() {
MonitorConfig monitorConfig = new MonitorConfig();
super.build(monitorConfig);
monitorConfig.setProtocol(protocol);
monitorConfig.setAddress(address);
monitorConfig.setUsername(username);
monitorConfig.setPassword(password);
monitorConfig.setGroup(group);
monitorConfig.setVersion(version);
monitorConfig.setInterval(interval);
monitorConfig.setParameters(parameters);
monitorConfig.setDefault(isDefault);
return monitorConfig;
}
@Override
protected MonitorBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,419 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ProtocolConfig;
import java.util.Map;
/**
* This is a builder for build {@link ProtocolConfig}.
*
* @since 2.7
*/
public class ProtocolBuilder extends AbstractBuilder<ProtocolConfig, ProtocolBuilder> {
/**
* Protocol name
*/
private String name;
/**
* Service ip address (when there are multiple network cards available)
*/
private String host;
/**
* Service port
*/
private Integer port;
/**
* Context path
*/
private String contextpath;
/**
* Thread pool
*/
private String threadpool;
/**
* Thread pool core thread size
*/
private Integer corethreads;
/**
* Thread pool size (fixed size)
*/
private Integer threads;
/**
* IO thread pool size (fixed size)
*/
private Integer iothreads;
/**
* Thread pool's queue length
*/
private Integer queues;
/**
* Max acceptable connections
*/
private Integer accepts;
/**
* Protocol codec
*/
private String codec;
/**
* Serialization
*/
private String serialization;
/**
* Charset
*/
private String charset;
/**
* Payload max length
*/
private Integer payload;
/**
* Buffer size
*/
private Integer buffer;
/**
* Heartbeat interval
*/
private Integer heartbeat;
/**
* Access log
*/
private String accesslog;
/**
* Transfort
*/
private String transporter;
/**
* How information is exchanged
*/
private String exchanger;
/**
* Thread dispatch mode
*/
private String dispatcher;
/**
* Networker
*/
private String networker;
/**
* Sever impl
*/
private String server;
/**
* Client impl
*/
private String client;
/**
* Supported telnet commands, separated with comma.
*/
private String telnet;
/**
* Command line prompt
*/
private String prompt;
/**
* Status check
*/
private String status;
/**
* Whether to register
*/
private Boolean register;
/**
* whether it is a persistent connection
*/
//TODO add this to provider config
private Boolean keepAlive;
// TODO add this to provider config
private String optimizer;
/**
* The extension
*/
private String extension;
/**
* The customized parameters
*/
private Map<String, String> parameters;
/**
* If it's default
*/
private Boolean isDefault;
public ProtocolBuilder name(String name) {
this.name = name;
return getThis();
}
public ProtocolBuilder host(String host) {
this.host = host;
return getThis();
}
public ProtocolBuilder port(Integer port) {
this.port = port;
return getThis();
}
public ProtocolBuilder contextpath(String contextpath) {
this.contextpath = contextpath;
return getThis();
}
/**
* @see org.apache.dubbo.config.builders.ProtocolBuilder#contextpath(String)
* @param path
* @return ProtocolBuilder
*/
@Deprecated
public ProtocolBuilder path(String path) {
this.contextpath = path;
return getThis();
}
public ProtocolBuilder threadpool(String threadpool) {
this.threadpool = threadpool;
return getThis();
}
public ProtocolBuilder corethreads(Integer corethreads) {
this.corethreads = corethreads;
return getThis();
}
public ProtocolBuilder threads(Integer threads) {
this.threads = threads;
return getThis();
}
public ProtocolBuilder iothreads(Integer iothreads) {
this.iothreads = iothreads;
return getThis();
}
public ProtocolBuilder queues(Integer queues) {
this.queues = queues;
return getThis();
}
public ProtocolBuilder accepts(Integer accepts) {
this.accepts = accepts;
return getThis();
}
public ProtocolBuilder codec(String codec) {
this.codec = codec;
return getThis();
}
public ProtocolBuilder serialization(String serialization) {
this.serialization = serialization;
return getThis();
}
public ProtocolBuilder charset(String charset) {
this.charset = charset;
return getThis();
}
public ProtocolBuilder payload(Integer payload) {
this.payload = payload;
return getThis();
}
public ProtocolBuilder buffer(Integer buffer) {
this.buffer = buffer;
return getThis();
}
public ProtocolBuilder heartbeat(Integer heartbeat) {
this.heartbeat = heartbeat;
return getThis();
}
public ProtocolBuilder accesslog(String accesslog) {
this.accesslog = accesslog;
return getThis();
}
public ProtocolBuilder transporter(String transporter) {
this.transporter = transporter;
return getThis();
}
public ProtocolBuilder exchanger(String exchanger) {
this.exchanger = exchanger;
return getThis();
}
public ProtocolBuilder dispatcher(String dispatcher) {
this.dispatcher = dispatcher;
return getThis();
}
/**
* @see org.apache.dubbo.config.builders.ProtocolBuilder#dispatcher(String)
* @param dispather
* @return ProtocolBuilder
*/
@Deprecated
public ProtocolBuilder dispather(String dispather) {
this.dispatcher = dispather;
return getThis();
}
public ProtocolBuilder networker(String networker) {
this.networker = networker;
return getThis();
}
public ProtocolBuilder server(String server) {
this.server = server;
return getThis();
}
public ProtocolBuilder client(String client) {
this.client = client;
return getThis();
}
public ProtocolBuilder telnet(String telnet) {
this.telnet = telnet;
return getThis();
}
public ProtocolBuilder prompt(String prompt) {
this.prompt = prompt;
return getThis();
}
public ProtocolBuilder status(String status) {
this.status = status;
return getThis();
}
public ProtocolBuilder register(Boolean register) {
this.register = register;
return getThis();
}
public ProtocolBuilder keepAlive(Boolean keepAlive) {
this.keepAlive = keepAlive;
return getThis();
}
public ProtocolBuilder optimizer(String optimizer) {
this.optimizer = optimizer;
return getThis();
}
public ProtocolBuilder extension(String extension) {
this.extension = extension;
return getThis();
}
public ProtocolBuilder appendParameter(String key, String value) {
this.parameters = appendParameter(parameters, key, value);
return getThis();
}
public ProtocolBuilder appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(parameters, appendParameters);
return getThis();
}
public ProtocolBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public ProtocolConfig build() {
ProtocolConfig protocolConfig = new ProtocolConfig();
super.build(protocolConfig);
protocolConfig.setAccepts(accepts);
protocolConfig.setAccesslog(accesslog);
protocolConfig.setBuffer(buffer);
protocolConfig.setCharset(charset);
protocolConfig.setClient(client);
protocolConfig.setCodec(codec);
protocolConfig.setContextpath(contextpath);
protocolConfig.setCorethreads(corethreads);
protocolConfig.setDefault(isDefault);
protocolConfig.setDispatcher(dispatcher);
protocolConfig.setExchanger(exchanger);
protocolConfig.setExtension(extension);
protocolConfig.setHeartbeat(heartbeat);
protocolConfig.setHost(host);
protocolConfig.setIothreads(iothreads);
protocolConfig.setKeepAlive(keepAlive);
protocolConfig.setName(name);
protocolConfig.setNetworker(networker);
protocolConfig.setOptimizer(optimizer);
protocolConfig.setParameters(parameters);
protocolConfig.setPayload(payload);
protocolConfig.setPort(port);
protocolConfig.setPrompt(prompt);
protocolConfig.setQueues(queues);
protocolConfig.setRegister(register);
protocolConfig.setSerialization(serialization);
protocolConfig.setServer(server);
protocolConfig.setStatus(status);
protocolConfig.setTelnet(telnet);
protocolConfig.setThreadpool(threadpool);
protocolConfig.setThreads(threads);
protocolConfig.setTransporter(transporter);
return protocolConfig;
}
@Override
protected ProtocolBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,293 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ProviderConfig;
/**
* This is a builder for build {@link ProviderConfig}.
*
* @since 2.7
*/
public class ProviderBuilder extends AbstractServiceBuilder<ProviderConfig, ProviderBuilder> {
/**
* Service ip addresses (used when there are multiple network cards available)
*/
private String host;
/**
* Service port
*/
private Integer port;
/**
* Context path
*/
private String contextpath;
/**
* Thread pool
*/
private String threadpool;
/**
* Thread pool size (fixed size)
*/
private Integer threads;
/**
* IO thread pool size (fixed size)
*/
private Integer iothreads;
/**
* Thread pool queue length
*/
private Integer queues;
/**
* Max acceptable connections
*/
private Integer accepts;
/**
* Protocol codec
*/
private String codec;
/**
* The serialization charset
*/
private String charset;
/**
* Payload max length
*/
private Integer payload;
/**
* The network io buffer size
*/
private Integer buffer;
/**
* Transporter
*/
private String transporter;
/**
* How information gets exchanged
*/
private String exchanger;
/**
* Thread dispatching mode
*/
private String dispatcher;
/**
* Networker
*/
private String networker;
/**
* The server-side implementation model of the protocol
*/
private String server;
/**
* The client-side implementation model of the protocol
*/
private String client;
/**
* Supported telnet commands, separated with comma.
*/
private String telnet;
/**
* Command line prompt
*/
private String prompt;
/**
* Status check
*/
private String status;
/**
* Wait time when stop
*/
private Integer wait;
/**
* Whether to use the default protocol
*/
private Boolean isDefault;
public ProviderBuilder host(String host) {
this.host = host;
return getThis();
}
public ProviderBuilder port(Integer port) {
this.port = port;
return getThis();
}
public ProviderBuilder contextPath(String contextPath) {
this.contextpath = contextPath;
return getThis();
}
public ProviderBuilder threadPool(String threadPool) {
this.threadpool = threadPool;
return getThis();
}
public ProviderBuilder threads(Integer threads) {
this.threads = threads;
return getThis();
}
public ProviderBuilder ioThreads(Integer ioThreads) {
this.iothreads = ioThreads;
return getThis();
}
public ProviderBuilder queues(Integer queues) {
this.queues = queues;
return getThis();
}
public ProviderBuilder accepts(Integer accepts) {
this.accepts = accepts;
return getThis();
}
public ProviderBuilder codec(String codec) {
this.codec = codec;
return getThis();
}
public ProviderBuilder charset(String charset) {
this.charset = charset;
return getThis();
}
public ProviderBuilder payload(Integer payload) {
this.payload = payload;
return getThis();
}
public ProviderBuilder buffer(Integer buffer) {
this.buffer = buffer;
return getThis();
}
public ProviderBuilder transporter(String transporter) {
this.transporter = transporter;
return getThis();
}
public ProviderBuilder exchanger(String exchanger) {
this.exchanger = exchanger;
return getThis();
}
public ProviderBuilder dispatcher(String dispatcher) {
this.dispatcher = dispatcher;
return getThis();
}
public ProviderBuilder networker(String networker) {
this.networker = networker;
return getThis();
}
public ProviderBuilder server(String server) {
this.server = server;
return getThis();
}
public ProviderBuilder client(String client) {
this.client = client;
return getThis();
}
public ProviderBuilder telnet(String telnet) {
this.telnet = telnet;
return getThis();
}
public ProviderBuilder prompt(String prompt) {
this.prompt = prompt;
return getThis();
}
public ProviderBuilder status(String status) {
this.status = status;
return getThis();
}
public ProviderBuilder wait(Integer wait) {
this.wait = wait;
return getThis();
}
public ProviderBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public ProviderConfig build() {
ProviderConfig provider = new ProviderConfig();
super.build(provider);
provider.setHost(host);
provider.setPort(port);
provider.setContextpath(contextpath);
provider.setThreadpool(threadpool);
provider.setThreads(threads);
provider.setIothreads(iothreads);
provider.setQueues(queues);
provider.setAccepts(accepts);
provider.setCodec(codec);
provider.setPayload(payload);
provider.setCharset(charset);
provider.setBuffer(buffer);
provider.setTransporter(transporter);
provider.setExchanger(exchanger);
provider.setDispatcher(dispatcher);
provider.setNetworker(networker);
provider.setServer(server);
provider.setClient(client);
provider.setTelnet(telnet);
provider.setPrompt(prompt);
provider.setStatus(status);
provider.setWait(wait);
provider.setDefault(isDefault);
return provider;
}
@Override
protected ProviderBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,134 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ReferenceConfig;
import java.util.ArrayList;
import java.util.List;
/**
* This is a builder for build {@link ReferenceConfig}.
*
* @since 2.7
*/
public class ReferenceBuilder<T> extends AbstractReferenceBuilder<ReferenceConfig, ReferenceBuilder<T>> {
/**
* The interface name of the reference service
*/
private String interfaceName;
/**
* The interface class of the reference service
*/
private Class<?> interfaceClass;
/**
* client type
*/
private String client;
/**
* The url for peer-to-peer invocation
*/
private String url;
/**
* The method configs
*/
private List<MethodConfig> methods;
/**
* The consumer config (default)
*/
private ConsumerConfig consumer;
/**
* Only the service provider of the specified protocol is invoked, and other protocols are ignored.
*/
private String protocol;
public ReferenceBuilder<T> interfaceName(String interfaceName) {
this.interfaceName = interfaceName;
return getThis();
}
public ReferenceBuilder<T> interfaceClass(Class<?> interfaceClass) {
this.interfaceClass = interfaceClass;
return getThis();
}
public ReferenceBuilder<T> client(String client) {
this.client = client;
return getThis();
}
public ReferenceBuilder<T> url(String url) {
this.url = url;
return getThis();
}
public ReferenceBuilder<T> addMethods(List<MethodConfig> methods) {
if (this.methods == null) {
this.methods = new ArrayList<>();
}
this.methods.addAll(methods);
return getThis();
}
public ReferenceBuilder<T> addMethod(MethodConfig method) {
if (this.methods == null) {
this.methods = new ArrayList<>();
}
this.methods.add(method);
return getThis();
}
public ReferenceBuilder<T> consumer(ConsumerConfig consumer) {
this.consumer = consumer;
return getThis();
}
public ReferenceBuilder<T> protocol(String protocol) {
this.protocol = protocol;
return getThis();
}
public ReferenceConfig<T> build() {
ReferenceConfig<T> reference = new ReferenceConfig<>();
super.build(reference);
reference.setInterface(interfaceName);
if (interfaceClass != null) {
reference.setInterface(interfaceClass);
}
reference.setClient(client);
reference.setUrl(url);
reference.setMethods(methods);
reference.setConsumer(consumer);
reference.setProtocol(protocol);
return reference;
}
@Override
protected ReferenceBuilder<T> getThis() {
return this;
}
}

View File

@ -0,0 +1,309 @@
/*
* 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.config.builders;
import java.util.Map;
import org.apache.dubbo.config.RegistryConfig;
/**
* This is a builder for build {@link RegistryConfig}.
*
* @since 2.7
*/
public class RegistryBuilder extends AbstractBuilder<RegistryConfig, RegistryBuilder> {
/**
* Register center address
*/
private String address;
/**
* Username to login register center
*/
private String username;
/**
* Password to login register center
*/
private String password;
/**
* Default port for register center
*/
private Integer port;
/**
* Protocol for register center
*/
private String protocol;
/**
* Network transmission type
*/
private String transporter;
private String server;
private String client;
private String cluster;
/**
* The group the services registry in
*/
private String group;
private String version;
/**
* Request timeout in milliseconds for register center
*/
private Integer timeout;
/**
* Session timeout in milliseconds for register center
*/
private Integer session;
/**
* File for saving register center dynamic list
*/
private String file;
/**
* Wait time before stop
*/
private Integer wait;
/**
* Whether to check if register center is available when boot up
*/
private Boolean check;
/**
* Whether to allow dynamic service to register on the register center
*/
private Boolean dynamic;
/**
* Whether to export service on the register center
*/
private Boolean register;
/**
* Whether allow to subscribe service on the register center
*/
private Boolean subscribe;
/**
* The customized parameters
*/
private Map<String, String> parameters;
/**
* Whether it's default
*/
private Boolean isDefault;
/**
* Simple the registry. both useful for provider and consumer
*
* @since 2.7.0
*/
private Boolean simplified;
/**
* After simplify the registry, should add some paramter individually. just for provider.
* <p>
* such as: extra-keys = A,b,c,d
*
* @since 2.7.0
*/
private String extraKeys;
public RegistryBuilder address(String address) {
this.address = address;
return getThis();
}
public RegistryBuilder username(String username) {
this.username = username;
return getThis();
}
public RegistryBuilder password(String password) {
this.password = password;
return getThis();
}
public RegistryBuilder port(Integer port) {
this.port = port;
return getThis();
}
public RegistryBuilder protocol(String protocol) {
this.protocol = protocol;
return getThis();
}
public RegistryBuilder transporter(String transporter) {
this.transporter = transporter;
return getThis();
}
/**
* @param transport
* @see #transporter(String)
* @deprecated
*/
@Deprecated
public RegistryBuilder transport(String transport) {
this.transporter = transport;
return getThis();
}
public RegistryBuilder server(String server) {
this.server = server;
return getThis();
}
public RegistryBuilder client(String client) {
this.client = client;
return getThis();
}
public RegistryBuilder cluster(String cluster) {
this.cluster = cluster;
return getThis();
}
public RegistryBuilder group(String group) {
this.group = group;
return getThis();
}
public RegistryBuilder version(String version) {
this.version = version;
return getThis();
}
public RegistryBuilder timeout(Integer timeout) {
this.timeout = timeout;
return getThis();
}
public RegistryBuilder session(Integer session) {
this.session = session;
return getThis();
}
public RegistryBuilder file(String file) {
this.file = file;
return getThis();
}
/**
* @param wait
* @see org.apache.dubbo.config.builders.ProviderBuilder#wait(Integer)
* @deprecated
*/
@Deprecated
public RegistryBuilder wait(Integer wait) {
this.wait = wait;
return getThis();
}
public RegistryBuilder isCheck(Boolean check) {
this.check = check;
return getThis();
}
public RegistryBuilder isDynamic(Boolean dynamic) {
this.dynamic = dynamic;
return getThis();
}
public RegistryBuilder register(Boolean register) {
this.register = register;
return getThis();
}
public RegistryBuilder subscribe(Boolean subscribe) {
this.subscribe = subscribe;
return getThis();
}
public RegistryBuilder appendParameter(String key, String value) {
this.parameters = appendParameter(parameters, key, value);
return getThis();
}
public RegistryBuilder appendParameters(Map<String, String> appendParameters) {
this.parameters = appendParameters(parameters, appendParameters);
return getThis();
}
public RegistryBuilder isDefault(Boolean isDefault) {
this.isDefault = isDefault;
return getThis();
}
public RegistryBuilder simplified(Boolean simplified) {
this.simplified = simplified;
return getThis();
}
public RegistryBuilder extraKeys(String extraKeys) {
this.extraKeys = extraKeys;
return getThis();
}
public RegistryConfig build() {
RegistryConfig registry = new RegistryConfig();
super.build(registry);
registry.setAddress(address);
registry.setCheck(check);
registry.setClient(client);
registry.setCluster(cluster);
registry.setDefault(isDefault);
registry.setDynamic(dynamic);
registry.setExtraKeys(extraKeys);
registry.setFile(file);
registry.setGroup(group);
registry.setParameters(parameters);
registry.setPassword(password);
registry.setPort(port);
registry.setProtocol(protocol);
registry.setRegister(register);
registry.setServer(server);
registry.setSession(session);
registry.setSimplified(simplified);
registry.setSubscribe(subscribe);
registry.setTimeout(timeout);
registry.setTransporter(transporter);
registry.setUsername(username);
registry.setVersion(version);
registry.setWait(wait);
return registry;
}
@Override
protected RegistryBuilder getThis() {
return this;
}
}

View File

@ -0,0 +1,152 @@
/*
* 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.config.builders;
import java.util.ArrayList;
import java.util.List;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.ServiceConfig;
/**
* This is a builder for build {@link ServiceConfig}.
*
* @since 2.7
*/
public class ServiceBuilder<U> extends AbstractServiceBuilder<ServiceConfig, ServiceBuilder<U>> {
/**
* The interface name of the exported service
*/
private String interfaceName;
/**
* The interface class of the exported service
*/
private Class<?> interfaceClass;
/**
* The reference of the interface implementation
*/
private U ref;
/**
* The service name
*/
private String path;
/**
* The method configuration
*/
private List<MethodConfig> methods;
/**
* The provider configuration
*/
private ProviderConfig provider;
/**
* The providerIds
*/
private String providerIds;
/**
* whether it is a GenericService
*/
private String generic;
public ServiceBuilder<U> interfaceName(String interfaceName) {
this.interfaceName = interfaceName;
return getThis();
}
public ServiceBuilder<U> interfaceClass(Class<?> interfaceClass) {
this.interfaceClass = interfaceClass;
return getThis();
}
public ServiceBuilder<U> ref(U ref) {
this.ref = ref;
return getThis();
}
public ServiceBuilder<U> path(String path) {
this.path = path;
return getThis();
}
public ServiceBuilder<U> addMethod(MethodConfig method) {
if (this.methods == null) {
this.methods = new ArrayList<>();
}
this.methods.add(method);
return getThis();
}
public ServiceBuilder<U> addMethods(List<? extends MethodConfig> methods) {
if (this.methods == null) {
this.methods = new ArrayList<>();
}
this.methods.addAll(methods);
return getThis();
}
public ServiceBuilder<U> provider(ProviderConfig provider) {
this.provider = provider;
return getThis();
}
public ServiceBuilder<U> providerIds(String providerIds) {
this.providerIds = providerIds;
return getThis();
}
public ServiceBuilder<U> generic(String generic) {
this.generic = generic;
return getThis();
}
@Override
public ServiceBuilder<U> mock(String mock) {
throw new IllegalArgumentException("mock doesn't support on provider side");
}
@Override
public ServiceBuilder<U> mock(Boolean mock) {
throw new IllegalArgumentException("mock doesn't support on provider side");
}
public ServiceConfig<U> build() {
ServiceConfig<U> serviceConfig = new ServiceConfig<>();
super.build(serviceConfig);
serviceConfig.setInterface(interfaceName);
serviceConfig.setInterface(interfaceClass);
serviceConfig.setRef(ref);
serviceConfig.setPath(path);
serviceConfig.setMethods(methods);
serviceConfig.setProvider(provider);
serviceConfig.setProviderIds(providerIds);
serviceConfig.setGeneric(generic);
return serviceConfig;
}
@Override
protected ServiceBuilder<U> getThis() {
return this;
}
}

View File

@ -0,0 +1,125 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.AbstractConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class AbstractBuilderTest {
@Test
void id() {
Builder builder = new Builder();
builder.id("id");
Assertions.assertEquals("id", builder.build().getId());
}
@Test
void prefix() {
Builder builder = new Builder();
builder.prefix("prefix");
Assertions.assertEquals("prefix", builder.build().getPrefix());
}
@Test
void appendParameter() {
Map<String, String> source = null;
Map<String, String> parameters = new HashMap<>();
parameters.put("default.num", "one");
parameters.put("num", "ONE");
source = AbstractBuilder.appendParameters(source, parameters);
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void appendParameter2() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one1");
source.put("num", "ONE1");
Map<String, String> parameters = new HashMap<>();
parameters.put("default.num", "one");
parameters.put("num", "ONE");
source = AbstractBuilder.appendParameters(source, parameters);
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = null;
source = AbstractBuilder.appendParameter(source, "default.num", "one");
source = AbstractBuilder.appendParameter(source, "num", "ONE");
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void appendParameters2() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one1");
source.put("num", "ONE1");
source = AbstractBuilder.appendParameter(source, "default.num", "one");
source = AbstractBuilder.appendParameter(source, "num", "ONE");
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void build() {
Builder builder = new Builder();
builder.id("id");
builder.prefix("prefix");
Config config = builder.build();
Config config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
private static class Builder extends AbstractBuilder<Config, Builder> {
public Config build() {
Config parameterConfig = new Config();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected Builder getThis() {
return this;
}
}
private static class Config extends AbstractConfig { }
}

View File

@ -0,0 +1,310 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
class AbstractInterfaceBuilderTest {
@Test
void local() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.local("GreetingMock");
Assertions.assertEquals("GreetingMock", builder.build().getLocal());
}
@Test
void local1() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.local((Boolean) null);
Assertions.assertNull(builder.build().getLocal());
builder.local(false);
Assertions.assertEquals("false", builder.build().getLocal());
builder.local(true);
Assertions.assertEquals("true", builder.build().getLocal());
}
@Test
void stub() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.stub("GreetingMock");
Assertions.assertEquals("GreetingMock", builder.build().getStub());
}
@Test
void stub1() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.stub((Boolean) null);
Assertions.assertNull(builder.build().getLocal());
builder.stub(false);
Assertions.assertEquals("false", builder.build().getStub());
builder.stub(true);
Assertions.assertEquals("true", builder.build().getStub());
}
@Test
void monitor() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.monitor("123");
MonitorConfig monitorConfig = new MonitorConfig("123");
Assertions.assertEquals(monitorConfig, builder.build().getMonitor());
}
@Test
void monitor1() {
MonitorConfig monitorConfig = new MonitorConfig("123");
InterfaceBuilder builder = new InterfaceBuilder();
builder.monitor(monitorConfig);
Assertions.assertEquals(monitorConfig, builder.build().getMonitor());
}
@Test
void proxy() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.proxy("mockproxyfactory");
Assertions.assertEquals("mockproxyfactory", builder.build().getProxy());
}
@Test
void cluster() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.cluster("mockcluster");
Assertions.assertEquals("mockcluster", builder.build().getCluster());
}
@Test
void filter() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.filter("mockfilter");
Assertions.assertEquals("mockfilter", builder.build().getFilter());
}
@Test
void listener() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.listener("mockinvokerlistener");
Assertions.assertEquals("mockinvokerlistener", builder.build().getListener());
}
@Test
void owner() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.owner("owner");
Assertions.assertEquals("owner", builder.build().getOwner());
}
@Test
void connections() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.connections(1);
Assertions.assertEquals(1, builder.build().getConnections().intValue());
}
@Test
void layer() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.layer("layer");
Assertions.assertEquals("layer", builder.build().getLayer());
}
@Test
void application() {
ApplicationConfig applicationConfig = new ApplicationConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.application(applicationConfig);
Assertions.assertEquals(applicationConfig, builder.build().getApplication());
}
@Test
void module() {
ModuleConfig moduleConfig = new ModuleConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.module(moduleConfig);
Assertions.assertEquals(moduleConfig, builder.build().getModule());
}
@Test
void addRegistries() {
RegistryConfig registryConfig = new RegistryConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.addRegistries(Collections.singletonList(registryConfig));
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registryConfig, builder.build().getRegistries().get(0));
Assertions.assertSame(registryConfig, builder.build().getRegistry());
}
@Test
void addRegistry() {
RegistryConfig registryConfig = new RegistryConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.addRegistry(registryConfig);
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registryConfig, builder.build().getRegistries().get(0));
Assertions.assertSame(registryConfig, builder.build().getRegistry());
}
@Test
void registryIds() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.registryIds("registryIds");
Assertions.assertEquals("registryIds", builder.build().getRegistryIds());
}
@Test
void onconnect() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.onconnect("onconnect");
Assertions.assertEquals("onconnect", builder.build().getOnconnect());
}
@Test
void ondisconnect() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.ondisconnect("ondisconnect");
Assertions.assertEquals("ondisconnect", builder.build().getOndisconnect());
}
@Test
void metadataReportConfig() {
MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.metadataReportConfig(metadataReportConfig);
Assertions.assertEquals(metadataReportConfig, builder.build().getMetadataReportConfig());
}
@Test
void configCenter() {
ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.configCenter(configCenterConfig);
Assertions.assertEquals(configCenterConfig, builder.build().getConfigCenter());
}
@Test
void callbacks() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.callbacks(2);
Assertions.assertEquals(2, builder.build().getCallbacks().intValue());
}
@Test
void scope() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.scope("scope");
Assertions.assertEquals("scope", builder.build().getScope());
}
@Test
void build() {
MonitorConfig monitorConfig = new MonitorConfig("123");
ApplicationConfig applicationConfig = new ApplicationConfig();
ModuleConfig moduleConfig = new ModuleConfig();
RegistryConfig registryConfig = new RegistryConfig();
MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.id("id").prefix("prefix").local(true).stub(false).monitor("123").proxy("mockproxyfactory").cluster("mockcluster")
.filter("mockfilter").listener("mockinvokerlistener").owner("owner").connections(1)
.layer("layer").application(applicationConfig).module(moduleConfig)
.addRegistry(registryConfig).registryIds("registryIds")
.onconnect("onconnet").ondisconnect("ondisconnect")
.metadataReportConfig(metadataReportConfig)
.configCenter(configCenterConfig)
.callbacks(2).scope("scope");
InterfaceConfig config = builder.build();
InterfaceConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertEquals("true", config.getLocal());
Assertions.assertEquals("false", config.getStub());
Assertions.assertEquals(monitorConfig, config.getMonitor());
Assertions.assertEquals("mockproxyfactory", config.getProxy());
Assertions.assertEquals("mockcluster", config.getCluster());
Assertions.assertEquals("mockfilter", config.getFilter());
Assertions.assertEquals("mockinvokerlistener", config.getListener());
Assertions.assertEquals("owner", config.getOwner());
Assertions.assertEquals(1, config.getConnections().intValue());
Assertions.assertEquals("layer", config.getLayer());
Assertions.assertEquals(applicationConfig, config.getApplication());
Assertions.assertEquals(moduleConfig, config.getModule());
Assertions.assertEquals(registryConfig, config.getRegistry());
Assertions.assertEquals("registryIds", config.getRegistryIds());
Assertions.assertEquals("onconnet", config.getOnconnect());
Assertions.assertEquals("ondisconnect", config.getOndisconnect());
Assertions.assertEquals(metadataReportConfig, config.getMetadataReportConfig());
Assertions.assertEquals(configCenterConfig, config.getConfigCenter());
Assertions.assertEquals(2, config.getCallbacks().intValue());
Assertions.assertEquals("scope", config.getScope());
Assertions.assertNotSame(config, config2);
}
private static class InterfaceBuilder extends AbstractInterfaceBuilder<InterfaceConfig, InterfaceBuilder> {
public InterfaceConfig build() {
InterfaceConfig config = new InterfaceConfig();
super.build(config);
return config;
}
@Override
protected InterfaceBuilder getThis() {
return this;
}
}
private static class InterfaceConfig extends AbstractInterfaceConfig { }
}

View File

@ -0,0 +1,195 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.AbstractMethodConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class AbstractMethodBuilderTest {
@Test
void timeout() {
MethodBuilder builder = new MethodBuilder();
builder.timeout(10);
Assertions.assertEquals(10, builder.build().getTimeout());
}
@Test
void retries() {
MethodBuilder builder = new MethodBuilder();
builder.retries(3);
Assertions.assertEquals(3, builder.build().getRetries());
}
@Test
void actives() {
MethodBuilder builder = new MethodBuilder();
builder.actives(3);
Assertions.assertEquals(3, builder.build().getActives());
}
@Test
void loadbalance() {
MethodBuilder builder = new MethodBuilder();
builder.loadbalance("mockloadbalance");
Assertions.assertEquals("mockloadbalance", builder.build().getLoadbalance());
}
@Test
void async() {
MethodBuilder builder = new MethodBuilder();
builder.async(true);
Assertions.assertTrue(builder.build().isAsync());
}
@Test
void sent() {
MethodBuilder builder = new MethodBuilder();
builder.sent(true);
Assertions.assertTrue(builder.build().getSent());
}
@Test
void mock() {
MethodBuilder builder = new MethodBuilder();
builder.mock("mock");
Assertions.assertEquals("mock", builder.build().getMock());
builder.mock("return null");
Assertions.assertEquals("return null", builder.build().getMock());
}
@Test
void mock1() {
MethodBuilder builder = new MethodBuilder();
builder.mock(true);
Assertions.assertEquals("true", builder.build().getMock());
builder.mock(false);
Assertions.assertEquals("false", builder.build().getMock());
}
@Test
void merger() {
MethodBuilder builder = new MethodBuilder();
builder.merger("merger");
Assertions.assertEquals("merger", builder.build().getMerger());
}
@Test
void cache() {
MethodBuilder builder = new MethodBuilder();
builder.cache("cache");
Assertions.assertEquals("cache", builder.build().getCache());
}
@Test
void validation() {
MethodBuilder builder = new MethodBuilder();
builder.validation("validation");
Assertions.assertEquals("validation", builder.build().getValidation());
}
@Test
void appendParameter() {
MethodBuilder builder = new MethodBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
MethodBuilder builder = new MethodBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void forks() {
MethodBuilder builder = new MethodBuilder();
builder.forks(5);
Assertions.assertEquals(5, builder.build().getForks());
}
@Test
void build() {
MethodBuilder builder = new MethodBuilder();
builder.id("id").prefix("prefix").timeout(1).retries(2).actives(3).loadbalance("mockloadbalance").async(true)
.sent(false).mock("mock").merger("merger").cache("cache").validation("validation")
.appendParameter("default.num", "one");
MethodConfig config = builder.build();
MethodConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertEquals(1, config.getTimeout());
Assertions.assertEquals(2, config.getRetries());
Assertions.assertEquals(3, config.getActives());
Assertions.assertEquals("mockloadbalance", config.getLoadbalance());
Assertions.assertTrue(config.isAsync());
Assertions.assertFalse(config.getSent());
Assertions.assertEquals("mock", config.getMock());
Assertions.assertEquals("merger", config.getMerger());
Assertions.assertEquals("cache", config.getCache());
Assertions.assertEquals("validation", config.getValidation());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertNotSame(config, config2);
}
private static class MethodBuilder extends AbstractMethodBuilder<MethodConfig, MethodBuilder> {
public MethodConfig build() {
MethodConfig parameterConfig = new MethodConfig();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected MethodBuilder getThis() {
return this;
}
}
private static class MethodConfig extends AbstractMethodConfig { }
}

View File

@ -0,0 +1,148 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.AbstractReferenceConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class AbstractReferenceBuilderTest {
@Test
void check() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.check(true);
Assertions.assertTrue(builder.build().isCheck());
builder.check(false);
Assertions.assertFalse(builder.build().isCheck());
}
@Test
void init() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.init(true);
Assertions.assertTrue(builder.build().isInit());
builder.init(false);
Assertions.assertFalse(builder.build().isInit());
}
@Test
void generic() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.generic(true);
Assertions.assertTrue(builder.build().isGeneric());
builder.generic(false);
Assertions.assertFalse(builder.build().isGeneric());
}
@Test
void generic1() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.generic("generic");
Assertions.assertEquals("generic", builder.build().getGeneric());
}
@Test
void injvm() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.injvm(true);
Assertions.assertTrue(builder.build().isInjvm());
builder.injvm(false);
Assertions.assertFalse(builder.build().isInjvm());
}
@Test
void lazy() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.lazy(true);
Assertions.assertTrue(builder.build().getLazy());
builder.lazy(false);
Assertions.assertFalse(builder.build().getLazy());
}
@Test
void reconnect() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.reconnect("reconnect");
Assertions.assertEquals("reconnect", builder.build().getReconnect());
}
@Test
void sticky() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.sticky(true);
Assertions.assertTrue(builder.build().getSticky());
builder.sticky(false);
Assertions.assertFalse(builder.build().getSticky());
}
@Test
void version() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void group() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void build() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.check(true).init(false).generic(true).injvm(false).lazy(true).reconnect("reconnect").sticky(false)
.version("version").group("group").id("id").prefix("prefix");
ReferenceConfig config = builder.build();
ReferenceConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isInit());
Assertions.assertTrue(config.isGeneric());
Assertions.assertFalse(config.isInjvm());
Assertions.assertTrue(config.getLazy());
Assertions.assertFalse(config.getSticky());
Assertions.assertEquals("reconnect", config.getReconnect());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertNotSame(config, config2);
}
private static class ReferenceBuilder extends AbstractReferenceBuilder<ReferenceConfig, ReferenceBuilder> {
public ReferenceConfig build() {
ReferenceConfig parameterConfig = new ReferenceConfig();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected ReferenceBuilder getThis() {
return this;
}
}
private static class ReferenceConfig extends AbstractReferenceConfig { }
}

View File

@ -0,0 +1,245 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.AbstractServiceConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
class AbstractServiceBuilderTest {
@Test
void version() {
ServiceBuilder builder = new ServiceBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void group() {
ServiceBuilder builder = new ServiceBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void deprecated() {
ServiceBuilder builder = new ServiceBuilder();
builder.deprecated(true);
Assertions.assertTrue(builder.build().isDeprecated());
builder.deprecated(false);
Assertions.assertFalse(builder.build().isDeprecated());
}
@Test
void delay() {
ServiceBuilder builder = new ServiceBuilder();
builder.delay(1000);
Assertions.assertEquals(1000, builder.build().getDelay());
}
@Test
void export() {
ServiceBuilder builder = new ServiceBuilder();
builder.export(true);
Assertions.assertTrue(builder.build().getExport());
builder.export(false);
Assertions.assertFalse(builder.build().getExport());
}
@Test
void weight() {
ServiceBuilder builder = new ServiceBuilder();
builder.weight(500);
Assertions.assertEquals(500, builder.build().getWeight());
}
@Test
void document() {
ServiceBuilder builder = new ServiceBuilder();
builder.document("http://dubbo.io");
Assertions.assertEquals("http://dubbo.io", builder.build().getDocument());
}
@Test
void dynamic() {
ServiceBuilder builder = new ServiceBuilder();
builder.dynamic(true);
Assertions.assertTrue(builder.build().isDynamic());
builder.dynamic(false);
Assertions.assertFalse(builder.build().isDynamic());
}
@Test
void token() {
ServiceBuilder builder = new ServiceBuilder();
builder.token("token");
Assertions.assertEquals("token", builder.build().getToken());
}
@Test
void token1() {
ServiceBuilder builder = new ServiceBuilder();
builder.token(true);
Assertions.assertEquals("true", builder.build().getToken());
builder.token(false);
Assertions.assertEquals("false",builder.build().getToken());
builder.token((Boolean) null);
Assertions.assertNull(builder.build().getToken());
}
@Test
void accesslog() {
ServiceBuilder builder = new ServiceBuilder();
builder.accesslog("accesslog");
Assertions.assertEquals("accesslog", builder.build().getAccesslog());
}
@Test
void accesslog1() {
ServiceBuilder builder = new ServiceBuilder();
builder.accesslog(true);
Assertions.assertEquals("true", builder.build().getAccesslog());
builder.accesslog(false);
Assertions.assertEquals("false",builder.build().getAccesslog());
builder.accesslog((Boolean) null);
Assertions.assertNull(builder.build().getAccesslog());
}
@Test
void addProtocols() {
ProtocolConfig protocol = new ProtocolConfig();
ServiceBuilder builder = new ServiceBuilder();
Assertions.assertNull(builder.build().getProtocols());
builder.addProtocols(Collections.singletonList(protocol));
Assertions.assertNotNull(builder.build().getProtocols());
Assertions.assertEquals(1, builder.build().getProtocols().size());
}
@Test
void addProtocol() {
ProtocolConfig protocol = new ProtocolConfig();
ServiceBuilder builder = new ServiceBuilder();
Assertions.assertNull(builder.build().getProtocols());
builder.addProtocol(protocol);
Assertions.assertNotNull(builder.build().getProtocols());
Assertions.assertEquals(1, builder.build().getProtocols().size());
Assertions.assertEquals(protocol, builder.build().getProtocol());
}
@Test
void protocolIds() {
ServiceBuilder builder = new ServiceBuilder();
builder.protocolIds("protocolIds");
Assertions.assertEquals("protocolIds", builder.build().getProtocolIds());
}
@Test
void tag() {
ServiceBuilder builder = new ServiceBuilder();
builder.tag("tag");
Assertions.assertEquals("tag", builder.build().getTag());
}
@Test
void executes() {
ServiceBuilder builder = new ServiceBuilder();
builder.executes(10);
Assertions.assertEquals(10, builder.build().getExecutes());
}
@Test
void register() {
ServiceBuilder builder = new ServiceBuilder();
builder.register(true);
Assertions.assertTrue(builder.build().isRegister());
builder.register(false);
Assertions.assertFalse(builder.build().isRegister());
}
@Test
void warmup() {
ServiceBuilder builder = new ServiceBuilder();
builder.warmup(100);
Assertions.assertEquals(100, builder.build().getWarmup());
}
@Test
void serialization() {
ServiceBuilder builder = new ServiceBuilder();
builder.serialization("serialization");
Assertions.assertEquals("serialization", builder.build().getSerialization());
}
@Test
void build() {
ProtocolConfig protocol = new ProtocolConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.version("version").group("group").deprecated(true).delay(1000).export(false).weight(1)
.document("document").dynamic(true).token("token").accesslog("accesslog")
.addProtocol(protocol).protocolIds("protocolIds").tag("tag").executes(100).register(false)
.warmup(200).serialization("serialization").id("id").prefix("prefix");
ServiceConfig config = builder.build();
ServiceConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("document", config.getDocument());
Assertions.assertEquals("token", config.getToken());
Assertions.assertEquals("accesslog", config.getAccesslog());
Assertions.assertEquals("protocolIds", config.getProtocolIds());
Assertions.assertEquals("tag", config.getTag());
Assertions.assertEquals("serialization", config.getSerialization());
Assertions.assertTrue(config.isDeprecated());
Assertions.assertFalse(config.getExport());
Assertions.assertTrue(config.isDynamic());
Assertions.assertFalse(config.isRegister());
Assertions.assertEquals(1000, config.getDelay());
Assertions.assertEquals(1, config.getWeight());
Assertions.assertEquals(100, config.getExecutes());
Assertions.assertEquals(200, config.getWarmup());
Assertions.assertNotSame(config, config2);
}
private static class ServiceBuilder extends AbstractServiceBuilder<ServiceConfig, ServiceBuilder> {
public ServiceConfig build() {
ServiceConfig parameterConfig = new ServiceConfig();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected ServiceBuilder getThis() {
return this;
}
}
private static class ServiceConfig extends AbstractServiceConfig {
}
}

View File

@ -0,0 +1,255 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
class ApplicationBuilderTest {
@Test
void name() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.name("app");
Assertions.assertEquals("app", builder.build().getName());
}
@Test
void version() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void owner() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.owner("owner");
Assertions.assertEquals("owner", builder.build().getOwner());
}
@Test
void organization() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.organization("organization");
Assertions.assertEquals("organization", builder.build().getOrganization());
}
@Test
void architecture() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.architecture("architecture");
Assertions.assertEquals("architecture", builder.build().getArchitecture());
}
@Test
void environment() {
ApplicationBuilder builder = new ApplicationBuilder();
Assertions.assertEquals("product", builder.build().getEnvironment());
builder.environment("develop");
Assertions.assertEquals("develop", builder.build().getEnvironment());
builder.environment("test");
Assertions.assertEquals("test", builder.build().getEnvironment());
builder.environment("product");
Assertions.assertEquals("product", builder.build().getEnvironment());
}
@Test
void compiler() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.compiler("compiler");
Assertions.assertEquals("compiler", builder.build().getCompiler());
}
@Test
void logger() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.logger("log4j");
Assertions.assertEquals("log4j", builder.build().getLogger());
}
@Test
void addRegistry() {
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.addRegistry(registry);
Assertions.assertNotNull(builder.build().getRegistry());
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registry, builder.build().getRegistry());
}
@Test
void addRegistries() {
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.addRegistries(Collections.singletonList(registry));
Assertions.assertNotNull(builder.build().getRegistry());
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registry, builder.build().getRegistry());
}
@Test
void registryIds() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.registryIds("registryIds");
Assertions.assertEquals("registryIds", builder.build().getRegistryIds());
}
@Test
void monitor() {
MonitorConfig monitor = new MonitorConfig("monitor-addr");
ApplicationBuilder builder = new ApplicationBuilder();
builder.monitor(monitor);
Assertions.assertSame(monitor, builder.build().getMonitor());
Assertions.assertEquals("monitor-addr", builder.build().getMonitor().getAddress());
}
@Test
void monitor1() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.monitor("monitor-addr");
Assertions.assertEquals("monitor-addr", builder.build().getMonitor().getAddress());
}
@Test
void isDefault() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
builder.isDefault(false);
Assertions.assertFalse(builder.build().isDefault());
builder.isDefault(null);
Assertions.assertNull(builder.build().isDefault());
}
@Test
void dumpDirectory() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.dumpDirectory("dumpDirectory");
Assertions.assertEquals("dumpDirectory", builder.build().getDumpDirectory());
}
@Test
void qosEnable() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.qosEnable(true);
Assertions.assertTrue(builder.build().getQosEnable());
builder.qosEnable(false);
Assertions.assertFalse(builder.build().getQosEnable());
builder.qosEnable(null);
Assertions.assertNull(builder.build().getQosEnable());
}
@Test
void qosPort() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.qosPort(8080);
Assertions.assertEquals(8080, builder.build().getQosPort());
}
@Test
void qosAcceptForeignIp() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.qosAcceptForeignIp(true);
Assertions.assertTrue(builder.build().getQosAcceptForeignIp());
builder.qosAcceptForeignIp(false);
Assertions.assertFalse(builder.build().getQosAcceptForeignIp());
builder.qosAcceptForeignIp(null);
Assertions.assertNull(builder.build().getQosAcceptForeignIp());
}
@Test
void shutwait() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.shutwait("shutwait");
Assertions.assertEquals("shutwait", builder.build().getShutwait());
}
@Test
void appendParameter() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
ApplicationBuilder builder = new ApplicationBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void build() {
MonitorConfig monitor = new MonitorConfig("monitor-addr");
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.id("id").prefix("prefix").name("name").version("version").owner("owner").organization("organization").architecture("architecture")
.environment("develop").compiler("compiler").logger("log4j").monitor(monitor).isDefault(false)
.dumpDirectory("dumpDirectory").qosEnable(true).qosPort(8080).qosAcceptForeignIp(false)
.shutwait("shutwait").registryIds("registryIds").addRegistry(registry)
.appendParameter("default.num", "one");
ApplicationConfig config = builder.build();
ApplicationConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("owner", config.getOwner());
Assertions.assertEquals("organization", config.getOrganization());
Assertions.assertEquals("architecture", config.getArchitecture());
Assertions.assertEquals("develop", config.getEnvironment());
Assertions.assertEquals("compiler", config.getCompiler());
Assertions.assertEquals("log4j", config.getLogger());
Assertions.assertSame(monitor, config.getMonitor());
Assertions.assertFalse(config.isDefault());
Assertions.assertEquals("dumpDirectory", config.getDumpDirectory());
Assertions.assertTrue(config.getQosEnable());
Assertions.assertEquals(8080, config.getQosPort());
Assertions.assertFalse(config.getQosAcceptForeignIp());
Assertions.assertEquals("shutwait", config.getShutwait());
Assertions.assertEquals("registryIds", config.getRegistryIds());
Assertions.assertSame(registry, config.getRegistry());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.builders;
import org.apache.dubbo.config.ArgumentConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ArgumentBuilderTest {
@Test
void index() {
ArgumentBuilder builder = new ArgumentBuilder();
builder.index(1);
Assertions.assertEquals(1, builder.build().getIndex());
}
@Test
void type() {
ArgumentBuilder builder = new ArgumentBuilder();
builder.type("int");
Assertions.assertEquals("int", builder.build().getType());
}
@Test
void callback() {
ArgumentBuilder builder = new ArgumentBuilder();
builder.callback(true);
Assertions.assertTrue(builder.build().isCallback());
builder.callback(false);
Assertions.assertFalse(builder.build().isCallback());
}
@Test
void build() {
ArgumentBuilder builder = new ArgumentBuilder();
builder.index(1).type("int").callback(true);
ArgumentConfig argument1 = builder.build();
ArgumentConfig argument2 = builder.build();
Assertions.assertTrue(argument1.isCallback());
Assertions.assertEquals("int", argument1.getType());
Assertions.assertEquals(1, argument1.getIndex());
Assertions.assertNotSame(argument1, argument2);
}
}

View File

@ -0,0 +1,177 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class ConfigCenterBuilderTest {
@Test
void protocol() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void address() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void cluster() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.cluster("cluster");
Assertions.assertEquals("cluster", builder.build().getCluster());
}
@Test
void namespace() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.namespace("namespace");
Assertions.assertEquals("namespace", builder.build().getNamespace());
}
@Test
void group() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void username() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void timeout() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.timeout(1000L);
Assertions.assertEquals(1000L, builder.build().getTimeout());
}
@Test
void highestPriority() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.highestPriority(true);
Assertions.assertTrue(builder.build().isHighestPriority());
}
@Test
void check() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.check(true);
Assertions.assertTrue(builder.build().isCheck());
}
@Test
void appName() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.appName("appName");
Assertions.assertEquals("appName", builder.build().getAppName());
}
@Test
void configFile() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.configFile("configFile");
Assertions.assertEquals("configFile", builder.build().getConfigFile());
}
@Test
void appConfigFile() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.appConfigFile("appConfigFile");
Assertions.assertEquals("appConfigFile", builder.build().getAppConfigFile());
}
@Test
void appendParameter() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void build() {
ConfigCenterBuilder builder = new ConfigCenterBuilder();
builder.check(true).protocol("protocol").address("address").appConfigFile("appConfigFile").appName("appName")
.cluster("cluster").configFile("configFile").group("group").highestPriority(false)
.namespace("namespace").password("password").timeout(1000L).username("usernama")
.appendParameter("default.num", "one").id("id").prefix("prefix");
ConfigCenterConfig config = builder.build();
ConfigCenterConfig config2 = builder.build();
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isHighestPriority());
Assertions.assertEquals(1000L, config.getTimeout());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("appConfigFile", config.getAppConfigFile());
Assertions.assertEquals("appName", config.getAppName());
Assertions.assertEquals("cluster", config.getCluster());
Assertions.assertEquals("configFile", config.getConfigFile());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("namespace", config.getNamespace());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("usernama", config.getUsername());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,95 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ConsumerConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ConsumerBuilderTest {
@Test
void isDefault() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.isDefault(false);
Assertions.assertFalse(builder.build().isDefault());
}
@Test
void client() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void threadPool() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.threadPool("threadPool");
Assertions.assertEquals("threadPool", builder.build().getThreadpool());
}
@Test
void coreThreads() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.coreThreads(10);
Assertions.assertEquals(10, builder.build().getCorethreads());
}
@Test
void threads() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.threads(100);
Assertions.assertEquals(100, builder.build().getThreads());
}
@Test
void queues() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.queues(200);
Assertions.assertEquals(200, builder.build().getQueues());
}
@Test
void shareConnections() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.shareConnections(300);
Assertions.assertEquals(300, builder.build().getShareconnections());
}
@Test
void build() {
ConsumerBuilder builder = new ConsumerBuilder();
builder.isDefault(true).client("client").threadPool("threadPool").coreThreads(10).threads(100).queues(200)
.shareConnections(300).id("id").prefix("prefix");
ConsumerConfig config = builder.build();
ConsumerConfig config2 = builder.build();
Assertions.assertTrue(config.isDefault());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("threadPool", config.getThreadpool());
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertEquals(10, config.getCorethreads());
Assertions.assertEquals(100, config.getThreads());
Assertions.assertEquals(200, config.getQueues());
Assertions.assertEquals(300, config.getShareconnections());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,151 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.MetadataReportConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class MetadataReportBuilderTest {
@Test
void address() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void username() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void timeout() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.timeout(1000);
Assertions.assertEquals(1000, builder.build().getTimeout());
}
@Test
void group() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void appendParameter() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void retryTimes() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.retryTimes(1);
Assertions.assertEquals(1, builder.build().getRetryTimes());
}
@Test
void retryPeriod() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.retryPeriod(2);
Assertions.assertEquals(2, builder.build().getRetryPeriod());
}
@Test
void cycleReport() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.cycleReport(true);
Assertions.assertTrue(builder.build().getCycleReport());
builder.cycleReport(false);
Assertions.assertFalse(builder.build().getCycleReport());
builder.cycleReport(null);
Assertions.assertNull(builder.build().getCycleReport());
}
@Test
void syncReport() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.syncReport(true);
Assertions.assertTrue(builder.build().getSyncReport());
builder.syncReport(false);
Assertions.assertFalse(builder.build().getSyncReport());
builder.syncReport(null);
Assertions.assertNull(builder.build().getSyncReport());
}
@Test
void build() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.address("address").username("username").password("password").timeout(1000).group("group")
.retryTimes(1).retryPeriod(2).cycleReport(true).syncReport(false)
.appendParameter("default.num", "one").id("id").prefix("prefix");
MetadataReportConfig config = builder.build();
MetadataReportConfig config2 = builder.build();
Assertions.assertTrue(config.getCycleReport());
Assertions.assertFalse(config.getSyncReport());
Assertions.assertEquals(1000, config.getTimeout());
Assertions.assertEquals(1, config.getRetryTimes());
Assertions.assertEquals(2, config.getRetryPeriod());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,189 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ArgumentConfig;
import org.apache.dubbo.config.MethodConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
class MethodBuilderTest {
@Test
void name() {
MethodBuilder builder = new MethodBuilder();
builder.name("name");
Assertions.assertEquals("name", builder.build().getName());
}
@Test
void stat() {
MethodBuilder builder = new MethodBuilder();
builder.stat(1);
Assertions.assertEquals(1, builder.build().getStat());
}
@Test
void retry() {
MethodBuilder builder = new MethodBuilder();
builder.retry(true);
Assertions.assertTrue(builder.build().isRetry());
}
@Test
void reliable() {
MethodBuilder builder = new MethodBuilder();
builder.reliable(true);
Assertions.assertTrue(builder.build().isReliable());
}
@Test
void executes() {
MethodBuilder builder = new MethodBuilder();
builder.executes(1);
Assertions.assertEquals(1, builder.build().getExecutes());
}
@Test
void deprecated() {
MethodBuilder builder = new MethodBuilder();
builder.deprecated(true);
Assertions.assertTrue(builder.build().getDeprecated());
}
@Test
void sticky() {
MethodBuilder builder = new MethodBuilder();
builder.sticky(true);
Assertions.assertTrue(builder.build().getSticky());
}
@Test
void isReturn() {
MethodBuilder builder = new MethodBuilder();
builder.isReturn(true);
Assertions.assertTrue(builder.build().isReturn());
}
@Test
void oninvoke() {
MethodBuilder builder = new MethodBuilder();
builder.oninvoke("on-invoke-object");
Assertions.assertEquals("on-invoke-object", builder.build().getOninvoke());
}
@Test
void oninvokeMethod() {
MethodBuilder builder = new MethodBuilder();
builder.oninvokeMethod("on-invoke-method");
Assertions.assertEquals("on-invoke-method", builder.build().getOninvokeMethod());
}
@Test
void onreturn() {
MethodBuilder builder = new MethodBuilder();
builder.onreturn("on-return-object");
Assertions.assertEquals("on-return-object", builder.build().getOnreturn());
}
@Test
void onreturnMethod() {
MethodBuilder builder = new MethodBuilder();
builder.onreturnMethod("on-return-method");
Assertions.assertEquals("on-return-method", builder.build().getOnreturnMethod());
}
@Test
void onthrow() {
MethodBuilder builder = new MethodBuilder();
builder.onthrow("on-throw-object");
Assertions.assertEquals("on-throw-object", builder.build().getOnthrow());
}
@Test
void onthrowMethod() {
MethodBuilder builder = new MethodBuilder();
builder.onthrowMethod("on-throw-method");
Assertions.assertEquals("on-throw-method", builder.build().getOnthrowMethod());
}
@Test
void addArguments() {
ArgumentConfig argument = new ArgumentConfig();
MethodBuilder builder = new MethodBuilder();
builder.addArguments(Collections.singletonList(argument));
Assertions.assertTrue(builder.build().getArguments().contains(argument));
Assertions.assertEquals(1, builder.build().getArguments().size());
}
@Test
void addArgument() {
ArgumentConfig argument = new ArgumentConfig();
MethodBuilder builder = new MethodBuilder();
builder.addArgument(argument);
Assertions.assertTrue(builder.build().getArguments().contains(argument));
Assertions.assertEquals(1, builder.build().getArguments().size());
}
@Test
void service() {
MethodBuilder builder = new MethodBuilder();
builder.service("service");
Assertions.assertEquals("service", builder.build().getService());
}
@Test
void serviceId() {
MethodBuilder builder = new MethodBuilder();
builder.serviceId("serviceId");
Assertions.assertEquals("serviceId", builder.build().getServiceId());
}
@Test
void build() {
ArgumentConfig argument = new ArgumentConfig();
MethodBuilder builder = new MethodBuilder();
builder.name("name").stat(1).retry(true).reliable(false).executes(2).deprecated(true).sticky(false)
.isReturn(true).oninvoke("on-invoke-object").oninvokeMethod("on-invoke-method").service("service")
.onreturn("on-return-object").onreturnMethod("on-return-method").serviceId("serviceId")
.onthrow("on-throw-object").onthrowMethod("on-throw-method").addArgument(argument);
MethodConfig config = builder.build();
MethodConfig config2 = builder.build();
Assertions.assertTrue(config.isRetry());
Assertions.assertFalse(config.isReliable());
Assertions.assertTrue(config.getDeprecated());
Assertions.assertFalse(config.getSticky());
Assertions.assertTrue(config.isReturn());
Assertions.assertEquals(1, config.getStat());
Assertions.assertEquals(2, config.getExecutes());
Assertions.assertEquals("on-invoke-object", config.getOninvoke());
Assertions.assertEquals("on-invoke-method", config.getOninvokeMethod());
Assertions.assertEquals("on-return-object", config.getOnreturn());
Assertions.assertEquals("on-return-method", config.getOnreturnMethod());
Assertions.assertEquals("on-throw-object", config.getOnthrow());
Assertions.assertEquals("on-throw-method", config.getOnthrowMethod());
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("service", config.getService());
Assertions.assertEquals("serviceId", config.getServiceId());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,112 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
class ModuleBuilderTest {
@Test
void name() {
ModuleBuilder builder = new ModuleBuilder();
builder.name("name");
Assertions.assertEquals("name", builder.build().getName());
}
@Test
void version() {
ModuleBuilder builder = new ModuleBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void owner() {
ModuleBuilder builder = new ModuleBuilder();
builder.owner("owner");
Assertions.assertEquals("owner", builder.build().getOwner());
}
@Test
void organization() {
ModuleBuilder builder = new ModuleBuilder();
builder.organization("organization");
Assertions.assertEquals("organization", builder.build().getOrganization());
}
@Test
void addRegistries() {
RegistryConfig registry = new RegistryConfig();
ModuleBuilder builder = new ModuleBuilder();
builder.addRegistries(Collections.singletonList(registry));
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertEquals(1, builder.build().getRegistries().size());
}
@Test
void addRegistry() {
RegistryConfig registry = new RegistryConfig();
ModuleBuilder builder = new ModuleBuilder();
builder.addRegistry(registry);
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertEquals(1, builder.build().getRegistries().size());
}
@Test
void monitor() {
MonitorConfig monitor = new MonitorConfig();
ModuleBuilder builder = new ModuleBuilder();
builder.monitor(monitor);
Assertions.assertSame(monitor, builder.build().getMonitor());
}
@Test
void isDefault() {
ModuleBuilder builder = new ModuleBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void build() {
RegistryConfig registry = new RegistryConfig();
MonitorConfig monitor = new MonitorConfig();
ModuleBuilder builder = new ModuleBuilder();
builder.name("name").version("version").owner("owner").organization("organization").addRegistry(registry)
.monitor(monitor).isDefault(false);
ModuleConfig config = builder.build();
ModuleConfig config2 = builder.build();
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("owner", config.getOwner());
Assertions.assertEquals("organization", config.getOrganization());
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertSame(monitor, builder.build().getMonitor());
Assertions.assertFalse(config.isDefault());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,135 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.MonitorConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class MonitorBuilderTest {
@Test
void protocol() {
MonitorBuilder builder = new MonitorBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void address() {
MonitorBuilder builder = new MonitorBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void username() {
MonitorBuilder builder = new MonitorBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
MonitorBuilder builder = new MonitorBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void group() {
MonitorBuilder builder = new MonitorBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void version() {
MonitorBuilder builder = new MonitorBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void interval() {
MonitorBuilder builder = new MonitorBuilder();
builder.interval("interval");
Assertions.assertEquals("interval", builder.build().getInterval());
}
@Test
void isDefault() {
MonitorBuilder builder = new MonitorBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void appendParameter() {
MonitorBuilder builder = new MonitorBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
MonitorBuilder builder = new MonitorBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void build() {
MonitorBuilder builder = new MonitorBuilder();
builder.protocol("protocol").address("address").group("group").interval("interval").isDefault(true)
.password("password").username("username").version("version")
.appendParameter("default.num", "one").id("id").prefix("prefix");
MonitorConfig config = builder.build();
MonitorConfig config2 = builder.build();
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("interval", config.getInterval());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertTrue(config.isDefault());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,338 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ProtocolConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class ProtocolBuilderTest {
@Test
void name() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.name("name");
Assertions.assertEquals("name", builder.build().getName());
}
@Test
void host() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.host("host");
Assertions.assertEquals("host", builder.build().getHost());
}
@Test
void port() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.port(8080);
Assertions.assertEquals(8080, builder.build().getPort());
}
@Test
void contextpath() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.contextpath("contextpath");
Assertions.assertEquals("contextpath", builder.build().getContextpath());
}
@Test
void path() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.path("path");
Assertions.assertEquals("path", builder.build().getPath());
}
@Test
void threadpool() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.threadpool("mockthreadpool");
Assertions.assertEquals("mockthreadpool", builder.build().getThreadpool());
}
@Test
void corethreads() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.corethreads(10);
Assertions.assertEquals(10, builder.build().getCorethreads());
}
@Test
void threads() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.threads(20);
Assertions.assertEquals(20, builder.build().getThreads());
}
@Test
void iothreads() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.iothreads(25);
Assertions.assertEquals(25, builder.build().getIothreads());
}
@Test
void queues() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.queues(30);
Assertions.assertEquals(30, builder.build().getQueues());
}
@Test
void accepts() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.accepts(35);
Assertions.assertEquals(35, builder.build().getAccepts());
}
@Test
void codec() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.codec("mockcodec");
Assertions.assertEquals("mockcodec", builder.build().getCodec());
}
@Test
void serialization() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.serialization("serialization");
Assertions.assertEquals("serialization", builder.build().getSerialization());
}
@Test
void charset() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.charset("utf-8");
Assertions.assertEquals("utf-8", builder.build().getCharset());
}
@Test
void payload() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.payload(40);
Assertions.assertEquals(40, builder.build().getPayload());
}
@Test
void buffer() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.buffer(1024);
Assertions.assertEquals(1024, builder.build().getBuffer());
}
@Test
void heartbeat() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.heartbeat(1000);
Assertions.assertEquals(1000, builder.build().getHeartbeat());
}
@Test
void accesslog() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.accesslog("accesslog");
Assertions.assertEquals("accesslog", builder.build().getAccesslog());
}
@Test
void transporter() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.transporter("mocktransporter");
Assertions.assertEquals("mocktransporter", builder.build().getTransporter());
}
@Test
void exchanger() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.exchanger("mockexchanger");
Assertions.assertEquals("mockexchanger", builder.build().getExchanger());
}
@Test
void dispatcher() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.dispatcher("mockdispatcher");
Assertions.assertEquals("mockdispatcher", builder.build().getDispatcher());
}
@Test
void dispather() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.dispather("mockdispatcher");
Assertions.assertEquals("mockdispatcher", builder.build().getDispather());
}
@Test
void networker() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.networker("networker");
Assertions.assertEquals("networker", builder.build().getNetworker());
}
@Test
void server() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.server("server");
Assertions.assertEquals("server", builder.build().getServer());
}
@Test
void client() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void telnet() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.telnet("mocktelnethandler");
Assertions.assertEquals("mocktelnethandler", builder.build().getTelnet());
}
@Test
void prompt() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.prompt("prompt");
Assertions.assertEquals("prompt", builder.build().getPrompt());
}
@Test
void status() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.status("mockstatuschecker");
Assertions.assertEquals("mockstatuschecker", builder.build().getStatus());
}
@Test
void register() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.register(true);
Assertions.assertTrue(builder.build().isRegister());
}
@Test
void keepAlive() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.keepAlive(true);
Assertions.assertTrue(builder.build().getKeepAlive());
}
@Test
void optimizer() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.optimizer("optimizer");
Assertions.assertEquals("optimizer", builder.build().getOptimizer());
}
@Test
void extension() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.extension("extension");
Assertions.assertEquals("extension", builder.build().getExtension());
}
@Test
void appendParameter() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
ProtocolBuilder builder = new ProtocolBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void isDefault() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void build() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.name("name").host("host").port(8080).contextpath("contextpath").threadpool("mockthreadpool")
.corethreads(1).threads(2).iothreads(3).queues(4).accepts(5).codec("mockcodec")
.serialization("serialization").charset("utf-8").payload(6).buffer(1024).heartbeat(1000)
.accesslog("accesslog").transporter("mocktransporter").exchanger("mockexchanger")
.dispatcher("mockdispatcher").networker("networker").server("server").client("client")
.telnet("mocktelnethandler").prompt("prompt").status("mockstatuschecker").register(true).keepAlive(false)
.optimizer("optimizer").extension("extension").isDefault(true)
.appendParameter("default.num", "one").id("id").prefix("prefix");
ProtocolConfig config = builder.build();
ProtocolConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(1, config.getCorethreads());
Assertions.assertEquals(2, config.getThreads());
Assertions.assertEquals(3, config.getIothreads());
Assertions.assertEquals(4, config.getQueues());
Assertions.assertEquals(5, config.getAccepts());
Assertions.assertEquals(6, config.getPayload());
Assertions.assertEquals(1024, config.getBuffer());
Assertions.assertEquals(1000, config.getHeartbeat());
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("host", config.getHost());
Assertions.assertEquals("contextpath", config.getContextpath());
Assertions.assertEquals("mockthreadpool", config.getThreadpool());
Assertions.assertEquals("mockcodec", config.getCodec());
Assertions.assertEquals("serialization", config.getSerialization());
Assertions.assertEquals("utf-8", config.getCharset());
Assertions.assertEquals("accesslog", config.getAccesslog());
Assertions.assertEquals("mocktransporter", config.getTransporter());
Assertions.assertEquals("mockexchanger", config.getExchanger());
Assertions.assertEquals("mockdispatcher", config.getDispatcher());
Assertions.assertEquals("networker", config.getNetworker());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("mocktelnethandler", config.getTelnet());
Assertions.assertEquals("prompt", config.getPrompt());
Assertions.assertEquals("mockstatuschecker", config.getStatus());
Assertions.assertEquals("optimizer", config.getOptimizer());
Assertions.assertEquals("extension", config.getExtension());
Assertions.assertTrue(config.isRegister());
Assertions.assertFalse(config.getKeepAlive());
Assertions.assertTrue(config.isDefault());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,227 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ProviderConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ProviderBuilderTest {
@Test
void setHost() {
ProviderBuilder builder = new ProviderBuilder();
builder.host("host");
Assertions.assertEquals("host", builder.build().getHost());
}
@Test
void port() {
ProviderBuilder builder = new ProviderBuilder();
builder.port(8080);
Assertions.assertEquals(8080, builder.build().getPort());
}
@Test
void contextPath() {
ProviderBuilder builder = new ProviderBuilder();
builder.contextPath("contextpath");
Assertions.assertEquals("contextpath", builder.build().getContextpath());
}
@Test
void threadPool() {
ProviderBuilder builder = new ProviderBuilder();
builder.threadPool("mockthreadpool");
Assertions.assertEquals("mockthreadpool", builder.build().getThreadpool());
}
@Test
void threads() {
ProviderBuilder builder = new ProviderBuilder();
builder.threads(20);
Assertions.assertEquals(20, builder.build().getThreads());
}
@Test
void ioThreads() {
ProviderBuilder builder = new ProviderBuilder();
builder.ioThreads(25);
Assertions.assertEquals(25, builder.build().getIothreads());
}
@Test
void queues() {
ProviderBuilder builder = new ProviderBuilder();
builder.queues(30);
Assertions.assertEquals(30, builder.build().getQueues());
}
@Test
void accepts() {
ProviderBuilder builder = new ProviderBuilder();
builder.accepts(35);
Assertions.assertEquals(35, builder.build().getAccepts());
}
@Test
void codec() {
ProviderBuilder builder = new ProviderBuilder();
builder.codec("mockcodec");
Assertions.assertEquals("mockcodec", builder.build().getCodec());
}
@Test
void charset() {
ProviderBuilder builder = new ProviderBuilder();
builder.charset("utf-8");
Assertions.assertEquals("utf-8", builder.build().getCharset());
}
@Test
void payload() {
ProviderBuilder builder = new ProviderBuilder();
builder.payload(40);
Assertions.assertEquals(40, builder.build().getPayload());
}
@Test
void buffer() {
ProviderBuilder builder = new ProviderBuilder();
builder.buffer(1024);
Assertions.assertEquals(1024, builder.build().getBuffer());
}
@Test
void transporter() {
ProviderBuilder builder = new ProviderBuilder();
builder.transporter("mocktransporter");
Assertions.assertEquals("mocktransporter", builder.build().getTransporter());
}
@Test
void exchanger() {
ProviderBuilder builder = new ProviderBuilder();
builder.exchanger("mockexchanger");
Assertions.assertEquals("mockexchanger", builder.build().getExchanger());
}
@Test
void dispatcher() {
ProviderBuilder builder = new ProviderBuilder();
builder.dispatcher("mockdispatcher");
Assertions.assertEquals("mockdispatcher", builder.build().getDispatcher());
}
@Test
void networker() {
ProviderBuilder builder = new ProviderBuilder();
builder.networker("networker");
Assertions.assertEquals("networker", builder.build().getNetworker());
}
@Test
void server() {
ProviderBuilder builder = new ProviderBuilder();
builder.server("server");
Assertions.assertEquals("server", builder.build().getServer());
}
@Test
void client() {
ProviderBuilder builder = new ProviderBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void telnet() {
ProviderBuilder builder = new ProviderBuilder();
builder.telnet("mocktelnethandler");
Assertions.assertEquals("mocktelnethandler", builder.build().getTelnet());
}
@Test
void prompt() {
ProviderBuilder builder = new ProviderBuilder();
builder.prompt("prompt");
Assertions.assertEquals("prompt", builder.build().getPrompt());
}
@Test
void status() {
ProviderBuilder builder = new ProviderBuilder();
builder.status("mockstatuschecker");
Assertions.assertEquals("mockstatuschecker", builder.build().getStatus());
}
@Test
void Wait() {
ProviderBuilder builder = new ProviderBuilder();
builder.wait(Integer.valueOf(1000));
Assertions.assertEquals(1000, builder.build().getWait());
}
@Test
void isDefault() {
ProviderBuilder builder = new ProviderBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void build() {
ProviderBuilder builder = new ProviderBuilder();
builder.host("host").port(8080).contextPath("contextpath").threadPool("mockthreadpool")
.threads(2).ioThreads(3).queues(4).accepts(5).codec("mockcodec")
.charset("utf-8").payload(6).buffer(1024).transporter("mocktransporter").exchanger("mockexchanger")
.dispatcher("mockdispatcher").networker("networker").server("server").client("client")
.telnet("mocktelnethandler").prompt("prompt").status("mockstatuschecker").wait(Integer.valueOf(1000))
.isDefault(true).id("id").prefix("prefix");
ProviderConfig config = builder.build();
ProviderConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(2, config.getThreads());
Assertions.assertEquals(3, config.getIothreads());
Assertions.assertEquals(4, config.getQueues());
Assertions.assertEquals(5, config.getAccepts());
Assertions.assertEquals(6, config.getPayload());
Assertions.assertEquals(1024, config.getBuffer());
Assertions.assertEquals(1000, config.getWait());
Assertions.assertEquals("host", config.getHost());
Assertions.assertEquals("contextpath", config.getContextpath());
Assertions.assertEquals("mockthreadpool", config.getThreadpool());
Assertions.assertEquals("mockcodec", config.getCodec());
Assertions.assertEquals("utf-8", config.getCharset());
Assertions.assertEquals("mocktransporter", config.getTransporter());
Assertions.assertEquals("mockexchanger", config.getExchanger());
Assertions.assertEquals("mockdispatcher", config.getDispatcher());
Assertions.assertEquals("networker", config.getNetworker());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("mocktelnethandler", config.getTelnet());
Assertions.assertEquals("prompt", config.getPrompt());
Assertions.assertEquals("mockstatuschecker", config.getStatus());
Assertions.assertTrue(config.isDefault());
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,114 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.api.DemoService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
class ReferenceBuilderTest {
@Test
void interfaceName() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.interfaceName(DemoService.class.getName());
Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", builder.build().getInterface());
}
@Test
void interfaceClass() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.interfaceClass(DemoService.class);
Assertions.assertEquals(DemoService.class, builder.build().getInterfaceClass());
}
@Test
void client() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void url() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.url("url");
Assertions.assertEquals("url", builder.build().getUrl());
}
@Test
void addMethods() {
MethodConfig method = new MethodConfig();
ReferenceBuilder builder = new ReferenceBuilder();
builder.addMethods(Collections.singletonList(method));
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void addMethod() {
MethodConfig method = new MethodConfig();
ReferenceBuilder builder = new ReferenceBuilder();
builder.addMethod(method);
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void consumer() {
ConsumerConfig consumer = new ConsumerConfig();
ReferenceBuilder builder = new ReferenceBuilder();
builder.consumer(consumer);
Assertions.assertSame(consumer, builder.build().getConsumer());
}
@Test
void protocol() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void build() {
ConsumerConfig consumer = new ConsumerConfig();
MethodConfig method = new MethodConfig();
ReferenceBuilder<DemoService> builder = new ReferenceBuilder<>();
builder.id("id").interfaceClass(DemoService.class).protocol("protocol").client("client").url("url")
.consumer(consumer).addMethod(method);
ReferenceConfig config = builder.build();
ReferenceConfig config2 = builder.build();
Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", config.getInterface());
Assertions.assertEquals(DemoService.class, config.getInterfaceClass());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("url", config.getUrl());
Assertions.assertEquals(consumer, config.getConsumer());
Assertions.assertTrue(config.getMethods().contains(method));
Assertions.assertEquals(1, config.getMethods().size());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,256 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.RegistryConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
class RegistryBuilderTest {
@Test
void address() {
RegistryBuilder builder = new RegistryBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void username() {
RegistryBuilder builder = new RegistryBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
RegistryBuilder builder = new RegistryBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void port() {
RegistryBuilder builder = new RegistryBuilder();
builder.port(8080);
Assertions.assertEquals(8080, builder.build().getPort());
}
@Test
void protocol() {
RegistryBuilder builder = new RegistryBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void transporter() {
RegistryBuilder builder = new RegistryBuilder();
builder.transporter("transporter");
Assertions.assertEquals("transporter", builder.build().getTransporter());
}
@Test
void transport() {
RegistryBuilder builder = new RegistryBuilder();
builder.transport("transport");
Assertions.assertEquals("transport", builder.build().getTransport());
}
@Test
void server() {
RegistryBuilder builder = new RegistryBuilder();
builder.server("server");
Assertions.assertEquals("server", builder.build().getServer());
}
@Test
void client() {
RegistryBuilder builder = new RegistryBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void cluster() {
RegistryBuilder builder = new RegistryBuilder();
builder.cluster("cluster");
Assertions.assertEquals("cluster", builder.build().getCluster());
}
@Test
void group() {
RegistryBuilder builder = new RegistryBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void version() {
RegistryBuilder builder = new RegistryBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void timeout() {
RegistryBuilder builder = new RegistryBuilder();
builder.timeout(1000);
Assertions.assertEquals(1000, builder.build().getTimeout());
}
@Test
void session() {
RegistryBuilder builder = new RegistryBuilder();
builder.session(2000);
Assertions.assertEquals(2000, builder.build().getSession());
}
@Test
void file() {
RegistryBuilder builder = new RegistryBuilder();
builder.file("file");
Assertions.assertEquals("file", builder.build().getFile());
}
@Test
void testWait() {
RegistryBuilder builder = new RegistryBuilder();
builder.wait(Integer.valueOf(1000));
Assertions.assertEquals(1000, builder.build().getWait());
}
@Test
void isCheck() {
RegistryBuilder builder = new RegistryBuilder();
builder.isCheck(true);
Assertions.assertTrue(builder.build().isCheck());
}
@Test
void isDynamic() {
RegistryBuilder builder = new RegistryBuilder();
builder.isDynamic(true);
Assertions.assertTrue(builder.build().isDynamic());
}
@Test
void register() {
RegistryBuilder builder = new RegistryBuilder();
builder.register(true);
Assertions.assertTrue(builder.build().isRegister());
}
@Test
void subscribe() {
RegistryBuilder builder = new RegistryBuilder();
builder.subscribe(true);
Assertions.assertTrue(builder.build().isSubscribe());
}
@Test
void appendParameter() {
RegistryBuilder builder = new RegistryBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
RegistryBuilder builder = new RegistryBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void isDefault() {
RegistryBuilder builder = new RegistryBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void simplified() {
RegistryBuilder builder = new RegistryBuilder();
builder.simplified(true);
Assertions.assertTrue(builder.build().getSimplified());
}
@Test
void extraKeys() {
RegistryBuilder builder = new RegistryBuilder();
builder.extraKeys("extraKeys");
Assertions.assertEquals("extraKeys", builder.build().getExtraKeys());
}
@Test
void build() {
RegistryBuilder builder = new RegistryBuilder();
builder.address("address").username("username").password("password").port(8080).protocol("protocol")
.transporter("transporter").server("server").client("client").cluster("cluster").group("group")
.version("version").timeout(1000).session(2000).file("file").wait(Integer.valueOf(10)).isCheck(true)
.isDynamic(false).register(true).subscribe(false).isDefault(true).simplified(false).extraKeys("A")
.appendParameter("default.num", "one").id("id").prefix("prefix");
RegistryConfig config = builder.build();
RegistryConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(1000, config.getTimeout());
Assertions.assertEquals(2000, config.getSession());
Assertions.assertEquals(10, config.getWait());
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isDynamic());
Assertions.assertTrue(config.isRegister());
Assertions.assertFalse(config.isSubscribe());
Assertions.assertTrue(config.isDefault());
Assertions.assertFalse(config.getSimplified());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("transporter", config.getTransporter());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("cluster", config.getCluster());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("file", config.getFile());
Assertions.assertEquals("A", config.getExtraKeys());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
}

View File

@ -0,0 +1,141 @@
/*
* 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.config.builders;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.api.Greeting;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_BEAN;
import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_DEFAULT;
import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
class ServiceBuilderTest {
@Test
public void testUniqueServiceName() throws Exception {
ServiceBuilder<Greeting> builder = new ServiceBuilder<>();
builder.group("dubbo").interfaceClass(Greeting.class).version("1.0.0");
ServiceConfig<Greeting> service = builder.build();
assertThat(service.getUniqueServiceName(), equalTo("dubbo/" + Greeting.class.getName() + ":1.0.0"));
}
@Test
void path() {
ServiceBuilder builder = new ServiceBuilder();
builder.path("path");
Assertions.assertEquals("path", builder.build().getPath());
}
@Test
void addMethod() {
MethodConfig method = new MethodConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.addMethod(method);
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void addMethods() {
MethodConfig method = new MethodConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.addMethods(Collections.singletonList(method));
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void provider() {
ProviderConfig provider = new ProviderConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.provider(provider);
Assertions.assertSame(provider, builder.build().getProvider());
}
@Test
void providerIds() {
ServiceBuilder builder = new ServiceBuilder();
builder.providerIds("providerIds");
Assertions.assertEquals("providerIds", builder.build().getProviderIds());
}
@Test
public void generic() throws Exception {
ServiceBuilder builder = new ServiceBuilder();
builder.generic(GENERIC_SERIALIZATION_DEFAULT);
assertThat(builder.build().getGeneric(), equalTo(GENERIC_SERIALIZATION_DEFAULT));
builder.generic(GENERIC_SERIALIZATION_NATIVE_JAVA);
assertThat(builder.build().getGeneric(), equalTo(GENERIC_SERIALIZATION_NATIVE_JAVA));
builder.generic(GENERIC_SERIALIZATION_BEAN);
assertThat(builder.build().getGeneric(), equalTo(GENERIC_SERIALIZATION_BEAN));
}
@Test
public void generic1() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ServiceBuilder builder = new ServiceBuilder();
builder.generic("illegal").build();
});
}
@Test
public void Mock() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ServiceBuilder builder = new ServiceBuilder();
builder.mock("true");
});
}
@Test
public void Mock1() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ServiceBuilder builder = new ServiceBuilder();
builder.mock(true);
});
}
@Test
void build() {
MethodConfig method = new MethodConfig();
ProviderConfig provider = new ProviderConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.path("path").addMethod(method).provider(provider).providerIds("providerIds")
.generic(GENERIC_SERIALIZATION_DEFAULT);
ServiceConfig config = builder.build();
ServiceConfig config2 = builder.build();
assertThat(config.getGeneric(), equalTo(GENERIC_SERIALIZATION_DEFAULT));
Assertions.assertEquals("path", config.getPath());
Assertions.assertEquals("providerIds", config.getProviderIds());
Assertions.assertSame(provider, config.getProvider());
Assertions.assertTrue(config.getMethods().contains(method));
Assertions.assertEquals(1, config.getMethods().size());
Assertions.assertNotSame(config, config2);
}
}