这段代码没有看教程(准确点说应该是连教程都没有)
这个类的作用呢,是保存每个节点组织的配置
这个类的构造函数里有一些property(属性),这些属性都是描述节点组织的,构造函数的目的就是生成一个叫sampleOrgs的容器,容器里面的每一个元素都是SampleOrg,这是hyperledger java sdk中的另一个类,是存放组织全部配置的类,包括peer、orderer、ca等的信息
最后在End2endIT.java中的checkConfig中有
testSampleOrgs = testConfig.getIntegrationTestsSampleOrgs();
testConfig后面的那个方法就是返回TestConfig类里面的sampleOrgs
/*
* Copyright 2016, 2017 IBM, DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved.
*
* Licensed 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.hyperledger.fabric.sdk.testutils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperledger.fabric.sdk.helper.Utils;
import org.hyperledger.fabric.sdkintegration.SampleOrg;
/**
* Config allows for a global config of the toolkit. Central location for all
* toolkit configuration defaults. Has a local config file that can override any
* property defaults. Config file can be relocated via a system property
* "org.hyperledger.fabric.sdk.configuration". Any property can be overridden
* with environment variable and then overridden
* with a java system property. Property hierarchy goes System property
* overrides environment variable which overrides config file for default values specified here.
*/
/**
* Test Configuration
*/
public class TestConfig {
private static final Log logger = LogFactory.getLog(TestConfig.class);
private static final String DEFAULT_CONFIG = "src/test/java/org/hyperledger/fabric/sdk/testutils.properties";
private static final String ORG_HYPERLEDGER_FABRIC_SDK_CONFIGURATION = "org.hyperledger.fabric.sdktest.configuration";
private static final String ORG_HYPERLEDGER_FABRIC_SDK_TEST_FABRIC_HOST = "ORG_HYPERLEDGER_FABRIC_SDK_TEST_FABRIC_HOST";
// private static final String LOCALHOST = //Change test to reference another
// host .. easier config for my testing on Windows !
// System.getenv(ORG_HYPERLEDGER_FABRIC_SDK_TEST_FABRIC_HOST) == null ?
// "localhost" : System.getenv(ORG_HYPERLEDGER_FABRIC_SDK_TEST_FABRIC_HOST);
private static final String LOCALHOST = // Change test to reference another host .. easier config for my testing on
// Windows !
System.getenv(ORG_HYPERLEDGER_FABRIC_SDK_TEST_FABRIC_HOST) == null ? "192.168.46.104"
: System.getenv(ORG_HYPERLEDGER_FABRIC_SDK_TEST_FABRIC_HOST);
private static final String PROPBASE = "org.hyperledger.fabric.sdktest.";
private static final String INVOKEWAITTIME = PROPBASE + "InvokeWaitTime";
private static final String DEPLOYWAITTIME = PROPBASE + "DeployWaitTime";
private static final String PROPOSALWAITTIME = PROPBASE + "ProposalWaitTime";
private static final String INTEGRATIONTESTS_ORG = PROPBASE + "integrationTests.org.";
private static final Pattern orgPat = Pattern
.compile("^" + Pattern.quote(INTEGRATIONTESTS_ORG) + "([^\\.]+)\\.mspid$");
private static final String INTEGRATIONTESTSTLS = PROPBASE + "integrationtests.tls";
// location switching between fabric cryptogen and configtxgen artifacts for
// v1.0 and v1.1 in src/test/fixture/sdkintegration/e2e-2Orgs
public static final String FAB_CONFIG_GEN_VERS = Objects
.equals(System.getenv("ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION"), "1.0.0") ? "v1.0" : "v1.1";
private static TestConfig config;
private static final Properties sdkProperties = new Properties();
private final boolean runningTLS;
private final boolean runningFabricCATLS;
public boolean isRunningFabricTLS() {
return runningFabricTLS;
}
private final boolean runningFabricTLS;
private static final HashMap<String, SampleOrg> sampleOrgs = new HashMap<>();
private TestConfig() {
File loadFile;
FileInputStream configProps;
try {
// 先加载配置文件,但是配置文件路径上没有对应文件,所以读不了配置,catch错误后也不进行处理,最后执行了finally的处理程序
loadFile = new File(System.getProperty(ORG_HYPERLEDGER_FABRIC_SDK_CONFIGURATION, DEFAULT_CONFIG))
.getAbsoluteFile();
System.out.println(" #### loadFile 配置文件路径: " + loadFile.getAbsolutePath());
logger.debug(String.format("Loading configuration from %s and it is present: %b", loadFile.toString(),
loadFile.exists()));
configProps = new FileInputStream(loadFile);
sdkProperties.load