Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for kernel internal shutdown #1133

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modAionImpl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dependencies {
testCompile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
testCompile "org.mockito:mockito-core:2.23.0"
testCompile 'com.google.truth:truth:0.42'
testCompile 'com.github.stefanbirkner:system-rules:1.19.0'
}

task preBuild(type: Exec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

import java.math.BigInteger;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.aion.crypto.ECKey;
import org.aion.db.impl.SystemExitCodes;
import org.aion.mcf.blockchain.Block;
import org.aion.types.AionAddress;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.core.ImportResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;

public class StandaloneBlockchainTest {
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

@Test
public void testStandaloneBlockchainGenerateAccounts() {
Expand All @@ -25,4 +32,25 @@ public void testStandaloneBlockchainGenerateAccounts() {
.isGreaterThan(BigInteger.ZERO);
}
}

@Test
public void testBlockChainShutdownhook() {
exit.expectSystemExitWithStatus(SystemExitCodes.NORMAL);

StandaloneBlockchain.Builder builder = new StandaloneBlockchain.Builder();
StandaloneBlockchain.Bundle bundle =
builder.withValidatorConfiguration("simple").withDefaultAccounts().build();

StandaloneBlockchain sb = bundle.bc;

AionBlockchainImpl.shutdownHook = 2;
Block block1 = sb.createBlock(sb.genesis, Collections.EMPTY_LIST, false, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
ImportResult result = sb.tryToConnect(block1);
assertThat(result.isBest()).isTrue();

Block block2 = sb.createBlock(block1, Collections.EMPTY_LIST, false, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));

// expect the system will be shutdown when import the block2
sb.tryToConnect(new BlockWrapper(block2));
}
}