Search in sources :

Example 1 with ExtendWith

use of org.junit.jupiter.api.extension.ExtendWith in project junit5 by junit-team.

the class ClasspathScannerTests method doesNotLoopInfinitelyWithCircularSymlinks.

@Test
@ExtendWith(TempDirectory.class)
void doesNotLoopInfinitelyWithCircularSymlinks(@Root Path tempDir) throws Exception {
    // Abort if running on Microsoft Windows since we are testing symbolic links
    assumeFalse(System.getProperty("os.name").toLowerCase().contains("win"));
    Path directory = Files.createDirectory(tempDir.resolve("directory"));
    Path symlink1 = Files.createSymbolicLink(tempDir.resolve("symlink1"), directory);
    Files.createSymbolicLink(directory.resolve("symlink2"), symlink1);
    List<Class<?>> classes = classpathScanner.scanForClassesInClasspathRoot(symlink1.toUri(), allClasses);
    assertThat(classes).isEmpty();
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 2 with ExtendWith

use of org.junit.jupiter.api.extension.ExtendWith in project hive by apache.

the class TestLlapDaemonLogging method testQueryRoutingNoLeakFileDescriptors.

@Test
@Log4jConfig("llap-daemon-routing-log4j2.properties")
@ExtendWith(LlapDaemonExtension.class)
@ExtendWith(DoNothingTCPServerExtension.class)
void testQueryRoutingNoLeakFileDescriptors(LlapDaemon daemon, DoNothingTCPServer amMockServer) throws IOException, InterruptedException {
    final int amPort = amMockServer.port();
    Credentials credentials = validSessionCredentials();
    String appId = "application_1540489363818_0021";
    for (int i = 0; i < 10; i++) {
        String queryId = "query" + i;
        int dagId = 1000 + i;
        daemon.registerDag(LlapDaemonTestUtils.buildRegisterDagRequest(appId, dagId, credentials));
        daemon.submitWork(LlapDaemonTestUtils.buildSubmitProtoRequest(appId, dagId, queryId, amPort, credentials));
        daemon.queryComplete(LlapDaemonTestUtils.buildQueryCompleteRequest(appId, dagId));
    }
    // Busy wait till all daemon tasks are treated
    while (!daemon.getExecutorsStatus().isEmpty()) {
        Thread.sleep(100);
    }
    // The IdlePurgePolicy used should close appenders after 5 seconds of inactivity.
    // Wait for 8 sec to give some margin.
    Thread.sleep(8000);
    Pattern pn = Pattern.compile("query\\d++-dag_1540489363818_0021_\\d{4}\\.log");
    assertEquals(0, findOpenFileDescriptors(pn).count());
}
Also used : Pattern(java.util.regex.Pattern) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.jupiter.api.Test) Log4jConfig(org.apache.hive.testutils.junit.extensions.Log4jConfig) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 3 with ExtendWith

use of org.junit.jupiter.api.extension.ExtendWith in project junit5 by junit-team.

the class ReflectionUtilsTests method getAllClasspathRootDirectories.

@Test
@ExtendWith(TempDirectory.class)
void getAllClasspathRootDirectories(@Root Path tempDirectory) throws Exception {
    Path root1 = tempDirectory.resolve("root1").toAbsolutePath();
    Path root2 = tempDirectory.resolve("root2").toAbsolutePath();
    String testClassPath = root1 + File.pathSeparator + root2;
    String originalClassPath = System.setProperty("java.class.path", testClassPath);
    try {
        createDirectories(root1, root2);
        assertThat(ReflectionUtils.getAllClasspathRootDirectories()).containsOnly(root1, root2);
    } finally {
        System.setProperty("java.class.path", originalClassPath);
    }
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 4 with ExtendWith

use of org.junit.jupiter.api.extension.ExtendWith in project spring-boot by spring-projects.

the class JtaAutoConfigurationTests method transactionManagerFromJndi.

@ParameterizedTest
@ExtendWith(JndiExtension.class)
@MethodSource("transactionManagerJndiEntries")
void transactionManagerFromJndi(JndiEntry jndiEntry, InitialContext initialContext) throws NamingException {
    jndiEntry.register(initialContext);
    this.context = new AnnotationConfigApplicationContext(JtaAutoConfiguration.class);
    JtaTransactionManager transactionManager = this.context.getBean(JtaTransactionManager.class);
    if (jndiEntry.value instanceof UserTransaction) {
        assertThat(transactionManager.getUserTransaction()).isEqualTo(jndiEntry.value);
        assertThat(transactionManager.getTransactionManager()).isNull();
    } else {
        assertThat(transactionManager.getUserTransaction()).isInstanceOf(UserTransactionAdapter.class);
        assertThat(transactionManager.getTransactionManager()).isEqualTo(jndiEntry.value);
    }
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 5 with ExtendWith

use of org.junit.jupiter.api.extension.ExtendWith in project spring-boot by spring-projects.

the class JtaAutoConfigurationTests method disableJtaSupport.

@Test
@ExtendWith(JndiExtension.class)
void disableJtaSupport(InitialContext initialContext) throws NamingException {
    new JndiEntry("java:comp/UserTransaction", UserTransaction.class).register(initialContext);
    this.context = new AnnotationConfigApplicationContext();
    TestPropertyValues.of("spring.jta.enabled:false").applyTo(this.context);
    this.context.register(JtaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeansOfType(JtaTransactionManager.class)).isEmpty();
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Aggregations

ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 Test (org.junit.jupiter.api.Test)7 Credentials (org.apache.hadoop.security.Credentials)3 Log4jConfig (org.apache.hive.testutils.junit.extensions.Log4jConfig)3 UserTransaction (jakarta.transaction.UserTransaction)2 Path (java.nio.file.Path)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Pattern (java.util.regex.Pattern)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)1