Skip to content

Commit

Permalink
FAB-9489 Network Config property overrides
Browse files Browse the repository at this point in the history
Minor fix and some more testing.

Change-Id: I983ee96c1619da58e0e2f8d3f5609acbc0f5e0b5
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Apr 12, 2018
1 parent 479b498 commit d75fe66
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Properties getPeerProperties(String name) throws InvalidArgumentException
* @return The orderer's properties.
* @throws InvalidArgumentException
*/
public Properties getOrderProperties(String name) throws InvalidArgumentException {
public Properties getOrdererProperties(String name) throws InvalidArgumentException {
return getNodeProperties("Orderer", name, orderers);

}
Expand Down
32 changes: 31 additions & 1 deletion src/test/java/org/hyperledger/fabric/sdk/NetworkConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package org.hyperledger.fabric.sdk;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
Expand All @@ -29,6 +28,7 @@
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;

import io.grpc.ManagedChannelBuilder;
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
import org.hyperledger.fabric.sdk.exception.NetworkConfigurationException;
import org.hyperledger.fabric.sdk.security.CryptoSuite;
Expand All @@ -39,6 +39,8 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hyperledger.fabric.sdk.testutils.TestUtils.getField;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -342,6 +344,13 @@ public void testLoadFromConfigFileYamlOverrides() throws Exception {
config.setPeerProperties(peerName, peerProperties);
}

for (String orderName : config.getOrdererNames()) {
Properties ordererProperties = config.getOrdererProperties(orderName);
ordererProperties.put("grpc.NettyChannelBuilderOption.maxInboundMessageSize", 9000000);
ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] {false});
config.setOrdererProperties(orderName, ordererProperties);
}

//HFClient client = HFClient.loadFromConfig(f);
assertNotNull(config);

Expand All @@ -363,6 +372,27 @@ public void testLoadFromConfigFileYamlOverrides() throws Exception {
assertNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveTimeout"));
assertNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));

Endpoint ep = new Endpoint(peer.getUrl(), properties);
ManagedChannelBuilder<?> channelBuilder = ep.getChannelBuilder();

assertEquals(5L * 60L * 1000000000L, getField(channelBuilder, "keepAliveTimeNanos"));
assertEquals(8L * 1000000000L, getField(channelBuilder, "keepAliveTimeoutNanos"));
assertEquals(true, getField(channelBuilder, "keepAliveWithoutCalls"));
}

for (Orderer orderer : channel.getOrderers()) {

Properties properties = orderer.getProperties();

assertNotNull(properties);
assertNotNull(properties.get("grpc.NettyChannelBuilderOption.maxInboundMessageSize"));
assertNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));

Endpoint ep = new Endpoint(orderer.getUrl(), properties);
ManagedChannelBuilder<?> channelBuilder = ep.getChannelBuilder();

assertEquals(9000000, getField(channelBuilder, "maxInboundMessageSize"));
assertEquals(false, getField(channelBuilder, "keepAliveWithoutCalls"));
}

}
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/org/hyperledger/fabric/sdk/testutils/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,33 @@ public static Object invokeMethod(Object o, String methodName, Object... args) t
public static Object getField(Object o, String fieldName) {

try {
final Field field = o.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
final Field field = getFieldInt(o.getClass(), fieldName);

return field.get(o);
} catch (Exception e) {
throw new RuntimeException("Cannot get value of field " + fieldName, e);
}
}

private static Field getFieldInt(Class o, String name) throws NoSuchFieldException {
Field ret;
try {
ret = o.getDeclaredField(name);
} catch (NoSuchFieldException e) {

Class superclass = o.getSuperclass();
if (null != superclass) {
ret = getFieldInt(superclass, name);

} else {
throw e;
}

}
ret.setAccessible(true);
return ret;
}

/**
* Reset config.
*/
Expand Down

0 comments on commit d75fe66

Please sign in to comment.