下面列出了怎么用org.junit.rules.TestName的API类实例代码及写法,或者点击链接到github查看源代码。
/** constructor */
public TestMajorCompaction(String compType) {
super();
name = new TestName();
// Set cache flush size to 1MB
conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024 * 1024);
conf.setInt(HConstants.HREGION_MEMSTORE_BLOCK_MULTIPLIER, 100);
compactionThreshold = conf.getInt("hbase.hstore.compactionThreshold", 3);
conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(compType));
secondRowBytes = START_KEY_BYTES.clone();
// Increment the least significant character so we get to next row.
secondRowBytes[START_KEY_BYTES.length - 1]++;
thirdRowBytes = START_KEY_BYTES.clone();
thirdRowBytes[START_KEY_BYTES.length - 1] =
(byte) (thirdRowBytes[START_KEY_BYTES.length - 1] + 2);
}
public MergeScreenShotGenerator(String testFilename, String testNameStr,
MergeTestFacilitator mtf, TestName testName) {
super();
this.testName = testName;
this.testFilename = testFilename;
this.mtf = mtf;
}
public static KubernetesCloud setupCloud(Object test, TestName name) throws KubernetesAuthException, IOException {
KubernetesCloud cloud = new KubernetesCloud("kubernetes");
// unique labels per test
cloud.setPodLabels(PodLabel.fromMap(getLabels(cloud, test, name)));
KubernetesClient client = cloud.connect();
// Run in our own testing namespace
// if there is a namespace specific for this branch (ie. kubernetes-plugin-test-master), use it
String branch = System.getenv("BRANCH_NAME");
if (StringUtils.isNotBlank(branch)) {
String namespaceWithBranch = String.format("%s-%s", DEFAULT_TESTING_NAMESPACE, branch);
LOGGER.log(FINE, "Trying to use namespace: {0}", testingNamespace);
try {
if (client.namespaces().withName(namespaceWithBranch).get() != null) {
testingNamespace = namespaceWithBranch;
}
} catch (KubernetesClientException e) {
// nothing to do
}
}
if (testingNamespace == null) {
testingNamespace = DEFAULT_TESTING_NAMESPACE;
if (client.namespaces().withName(testingNamespace).get() == null) {
LOGGER.log(INFO, "Creating namespace: {0}", testingNamespace);
client.namespaces().create(
new NamespaceBuilder().withNewMetadata().withName(testingNamespace).endMetadata().build());
}
}
LOGGER.log(INFO, "Using namespace {0} for branch {1}", new String[] { testingNamespace, branch });
cloud.setNamespace(testingNamespace);
client = cloud.connect();
return cloud;
}
/**
* Labels to add to the pods so we can match them to a specific build run, test class and method
*/
public static Map<String, String> getLabels(KubernetesCloud cloud, Object o, TestName name) {
HashMap<String, String> l = Maps.newHashMap(DEFAULT_LABELS);
if (cloud != null) {
l.putAll(cloud.getPodLabelsMap());
}
l.put("class", o.getClass().getSimpleName());
l.put("test", name.getMethodName());
return l;
}
public static TestRule getTimeoutRule(int timeout, TimeUnit unit) {
return IS_DEBUG ? new TestName() : Timeout.builder().withTimeout(timeout, unit).build();
}
/**
* If not enforced, the repeat rule applies only if the test is run in non-debug mode.
*/
public static TestRule getRepeatRule(final boolean enforce) {
return enforce || !IS_DEBUG ? new RepeatTestRule() : new TestName();
}
public static Map<String, String> getLabels(Object o, TestName name) {
return getLabels(null, o, name);
}
public SpaceQuotaHelperForTests(
HBaseTestingUtility testUtil, TestName testName, AtomicLong counter) {
this.testUtil = Objects.requireNonNull(testUtil);
this.testName = Objects.requireNonNull(testName);
this.counter = Objects.requireNonNull(counter);
}
@Override JmsTestRule newJmsTestRule(TestName testName) {
return new ArtemisJmsTestRule(testName);
}
@Override JmsTestRule newJmsTestRule(TestName testName) {
return new ArtemisJmsTestRule(testName);
}
ArtemisJmsTestRule(TestName testName) {
super(testName);
factory = new ActiveMQJMSConnectionFactory("vm://0");
factory.setProducerMaxRate(1); // to allow tests to use production order
}
JmsTestRule(TestName testName) {
this.testName = testName;
}
ActiveMQ(TestName testName) {
super(testName);
}
JmsTestRule newJmsTestRule(TestName testName) {
return new JmsTestRule.ActiveMQ(testName);
}
JmsTestRule newJmsTestRule(TestName testName) {
return new JmsTestRule.ActiveMQ(testName);
}