package org.wildfly.openssl;

import javax.net.ssl.SSLContext;
import org.junit.Test;

/**
 *
 * @author rmartinc
 */
public class LalaTest extends AbstractOpenSSLTest {

    private static final int NUM_THREADS = 10;

    @Test
    public void testThread() throws Exception {
        final SSLContext sslContext = SSLTestUtils.createSSLContext("openssl.TLS");

        /*
        // this part is to set the client auth before the multi-thread part
        final OpenSSLEngine sslEngine1 = (OpenSSLEngine) sslContext.createSSLEngine();
        sslEngine1.setWantClientAuth(true);
        sslEngine1.getSsl();
        sslEngine1.shutdown();*/

        Thread[] threads = new Thread[NUM_THREADS];
        for (int i = 0; i < NUM_THREADS; i++) {
            threads[i] = new Thread(() -> {
                final OpenSSLEngine sslEngine = (OpenSSLEngine) sslContext.createSSLEngine();
                sslEngine.setWantClientAuth(true);
                sslEngine.getSsl();
                sslEngine.shutdown();
            });
        }
        for (int i = 0; i < NUM_THREADS; i++) {
            threads[i].start();
        }
        for (int i = 0; i < NUM_THREADS; i++) {
            threads[i].join();
        }
    }
}
