Skip to content

Commit

Permalink
SkipOnSetupFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
VGalaxies committed Jun 11, 2024
1 parent 64a115b commit 3938e55
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.iotdb.subscription.it;

import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class SkipOnSetupFailure implements TestRule {

private static final String SET_UP_METHOD_NAME = "setUp";

@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() {
try {
base.evaluate();
} catch (final Throwable e) {
if (e.getStackTrace()[0].getMethodName().equals(SET_UP_METHOD_NAME)) {
e.printStackTrace();
throw new AssumptionViolatedException(
String.format(
"Skipping test due to setup failure for %s@%s",
description.getClassName(), description.getMethodName()));
}
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
import org.apache.iotdb.session.subscription.payload.SubscriptionMessage;
import org.apache.iotdb.session.subscription.payload.SubscriptionSessionDataSet;
import org.apache.iotdb.subscription.it.IoTDBSubscriptionITConstant;
import org.apache.iotdb.subscription.it.SkipOnSetupFailure;

import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -63,7 +66,7 @@ public class IoTDBSubscriptionRestartIT {

private static final Logger LOGGER = LoggerFactory.getLogger(IoTDBSubscriptionRestartIT.class);

private volatile boolean setupFailed = false;
@Rule public final TestRule skipOnSetupFailure = new SkipOnSetupFailure();

@Before
public void setUp() throws Exception {
Expand All @@ -76,14 +79,7 @@ public void setUp() throws Exception {
.setSchemaReplicationFactor(3)
.setDataReplicationFactor(2);

try {
EnvFactory.getEnv().initClusterEnvironment(3, 3);
} catch (final Throwable e) {
e.printStackTrace();
setupFailed = true;
return;
}
setupFailed = false;
EnvFactory.getEnv().initClusterEnvironment(3, 3);
}

@After
Expand All @@ -93,10 +89,6 @@ public void tearDown() throws Exception {

@Test
public void testSubscriptionAfterRestartCluster() throws Exception {
if (setupFailed) {
return;
}

final String host = EnvFactory.getEnv().getIP();
final int port = Integer.parseInt(EnvFactory.getEnv().getPort());

Expand Down Expand Up @@ -226,10 +218,6 @@ public void testSubscriptionAfterRestartCluster() throws Exception {

@Test
public void testSubscriptionAfterRestartDataNode() throws Exception {
if (setupFailed) {
return;
}

// Fetch ip and port from DN 0
final String host = EnvFactory.getEnv().getIP();
final int port = Integer.parseInt(EnvFactory.getEnv().getPort());
Expand Down Expand Up @@ -372,10 +360,6 @@ public void testSubscriptionAfterRestartDataNode() throws Exception {

@Test
public void testSubscriptionWhenConfigNodeLeaderChange() throws Exception {
if (setupFailed) {
return;
}

// Fetch ip and port from DN 0
final String host = EnvFactory.getEnv().getIP();
final int port = Integer.parseInt(EnvFactory.getEnv().getPort());
Expand Down

0 comments on commit 3938e55

Please sign in to comment.