Skip to content

Commit

Permalink
fix(NodeOptions): NodeOptions.copy() without base class RpcOptions fi…
Browse files Browse the repository at this point in the history
…elds. Fixes gh-889 (#902)

fix(NodeOptions): NodeOptions.copy() without base class RpcOptions fields. Fixes gh-889

Co-authored-by: “yanguanghui” <yanguanghui@betalpha.com>
  • Loading branch information
lfygh and “yanguanghui” authored Nov 16, 2022
1 parent c185f58 commit a1afcf8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Node options.
*
* @author boyan (boyan@alibaba-inc.com)
*
* @author lfyg
* 2018-Apr-04 2:59:12 PM
*/
public class NodeOptions extends RpcOptions implements Copiable<NodeOptions> {
Expand Down Expand Up @@ -435,6 +435,14 @@ public NodeOptions copy() {
nodeOptions.setSharedVoteTimer(this.sharedVoteTimer);
nodeOptions.setSharedStepDownTimer(this.sharedStepDownTimer);
nodeOptions.setSharedSnapshotTimer(this.sharedSnapshotTimer);

nodeOptions.setRpcConnectTimeoutMs(super.getRpcConnectTimeoutMs());
nodeOptions.setRpcDefaultTimeout(super.getRpcDefaultTimeout());
nodeOptions.setRpcInstallSnapshotTimeout(super.getRpcInstallSnapshotTimeout());
nodeOptions.setRpcProcessorThreadPoolSize(super.getRpcProcessorThreadPoolSize());
nodeOptions.setEnableRpcChecksum(super.isEnableRpcChecksum());
nodeOptions.setMetricRegistry(super.getMetricRegistry());

return nodeOptions;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 com.alipay.sofa.jraft.option;

import com.codahale.metrics.MetricRegistry;
import org.junit.Test;

import static org.junit.Assert.*;

public class NodeOptionsTest {

@Test
public void testCopyRpcOptionsRight() {
final NodeOptions nodeOptions = new NodeOptions();

assertEquals(1000, nodeOptions.getRpcConnectTimeoutMs());
assertEquals(5000, nodeOptions.getRpcDefaultTimeout());
assertEquals(5 * 60 * 1000, nodeOptions.getRpcInstallSnapshotTimeout());
assertEquals(80, nodeOptions.getRpcProcessorThreadPoolSize());
assertFalse(nodeOptions.isEnableRpcChecksum());
assertNull(nodeOptions.getMetricRegistry());

//change options
nodeOptions.setRpcConnectTimeoutMs(2000);
nodeOptions.setRpcDefaultTimeout(6000);
nodeOptions.setRpcInstallSnapshotTimeout(6 * 60 * 1000);
nodeOptions.setRpcProcessorThreadPoolSize(90);
nodeOptions.setEnableRpcChecksum(true);
nodeOptions.setMetricRegistry(new MetricRegistry());

//copy options
final NodeOptions copy = nodeOptions.copy();

assertEquals(2000, copy.getRpcConnectTimeoutMs());
assertEquals(6000, copy.getRpcDefaultTimeout());
assertEquals(6 * 60 * 1000, copy.getRpcInstallSnapshotTimeout());
assertEquals(90, copy.getRpcProcessorThreadPoolSize());
assertTrue(copy.isEnableRpcChecksum());
assertNotNull(copy.getMetricRegistry());
}
}

0 comments on commit a1afcf8

Please sign in to comment.