use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class IndexIT method createIndexesForDifferentLabelsConcurrently.
@Test
@Timeout(10)
void createIndexesForDifferentLabelsConcurrently() throws Throwable {
TokenWrite tokenWrite = tokenWriteInNewTransaction();
int label2 = tokenWrite.labelGetOrCreateForName("Label2");
commit();
LabelSchemaDescriptor anotherLabelDescriptor = SchemaDescriptor.forLabel(label2, propertyKeyId);
schemaWriteInNewTransaction().indexCreate(anotherLabelDescriptor, "my index");
Future<?> indexFuture = executorService.submit(createIndex(db, label(LABEL), PROPERTY_KEY));
indexFuture.get();
commit();
}
use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class KernelTransactionTerminationTest method closeTransaction.
@Test
@Timeout(TEST_RUN_TIME_SECS * 20)
void closeTransaction() throws Throwable {
BlockingQueue<Boolean> committerToTerminator = new LinkedBlockingQueue<>(1);
BlockingQueue<TerminatorAction> terminatorToCommitter = new LinkedBlockingQueue<>(1);
AtomicBoolean t1Done = new AtomicBoolean();
runTwoThreads(() -> {
committerToTerminator.clear();
terminatorToCommitter.clear();
t1Done.set(false);
}, tx -> {
Boolean terminatorShouldAct = committerToTerminator.poll();
if (terminatorShouldAct != null && terminatorShouldAct) {
TerminatorAction action = TerminatorAction.random();
action.executeOn(tx);
assertTrue(terminatorToCommitter.add(action));
}
t1Done.set(true);
}, tx -> {
CommitterAction committerAction = CommitterAction.random();
if (committerToTerminator.offer(true)) {
TerminatorAction terminatorAction = null;
try {
// This loop optimizes the wait instead of waiting potentially a long time for T1 when it would lose the race and not do anything
while (!t1Done.get() && terminatorAction == null) {
terminatorAction = terminatorToCommitter.poll(10, MILLISECONDS);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
if (terminatorAction != null) {
close(tx, committerAction, terminatorAction);
}
}
});
}
use of org.junit.jupiter.api.Timeout in project spring-framework by spring-projects.
the class AbstractSockJsIntegrationTests method fallbackAfterConnectTimeout.
@Test
@Timeout(5)
public void fallbackAfterConnectTimeout() throws Exception {
TestClientHandler clientHandler = new TestClientHandler();
this.testFilter.sleepDelayMap.put("/xhr_streaming", 10000L);
this.testFilter.sendErrorMap.put("/xhr_streaming", 503);
initSockJsClient(createXhrTransport());
this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class));
WebSocketSession clientSession = sockJsClient.doHandshake(clientHandler, this.baseUrl + "/echo").get();
assertThat(clientSession.getClass()).as("Fallback didn't occur").isEqualTo(XhrClientSockJsSession.class);
TextMessage message = new TextMessage("message1");
clientSession.sendMessage(message);
clientHandler.awaitMessage(message, 5000);
clientSession.close();
}
use of org.junit.jupiter.api.Timeout in project kafka by apache.
the class UtilsTest method testFileAsStringNamedPipe.
/**
* Test to read content of named pipe as string. As reading/writing to a pipe can block,
* timeout test after a minute (test finishes within 100 ms normally).
*/
@Timeout(60)
@Test
public void testFileAsStringNamedPipe() throws Exception {
// Create a temporary name for named pipe
Random random = new Random();
long n = random.nextLong();
n = n == Long.MIN_VALUE ? 0 : Math.abs(n);
// Use the name to create a FIFO in tmp directory
String tmpDir = System.getProperty("java.io.tmpdir");
String fifoName = "fifo-" + n + ".tmp";
File fifo = new File(tmpDir, fifoName);
Thread producerThread = null;
try {
Process mkFifoCommand = new ProcessBuilder("mkfifo", fifo.getCanonicalPath()).start();
mkFifoCommand.waitFor();
// Send some data to fifo and then read it back, but as FIFO blocks if the consumer isn't present,
// we need to send data in a separate thread.
final String testFileContent = "This is test";
producerThread = new Thread(() -> {
try {
Files.write(fifo.toPath(), testFileContent.getBytes());
} catch (IOException e) {
fail("Error when producing to fifo : " + e.getMessage());
}
}, "FIFO-Producer");
producerThread.start();
assertEquals(testFileContent, Utils.readFileAsString(fifo.getCanonicalPath()));
} finally {
Files.deleteIfExists(fifo.toPath());
if (producerThread != null) {
// Wait for thread to terminate
producerThread.join(30 * 1000);
assertFalse(producerThread.isAlive());
}
}
}
use of org.junit.jupiter.api.Timeout in project kafka by apache.
the class SenderTest method testForceShutdownWithIncompleteTransaction.
@Timeout(10L)
@Test
public void testForceShutdownWithIncompleteTransaction() {
// create a sender with retries = 1
int maxRetries = 1;
Metrics m = new Metrics();
SenderMetricsRegistry senderMetrics = new SenderMetricsRegistry(m);
try {
TransactionManager txnManager = new TransactionManager(logContext, "testForceShutdownWithIncompleteTransaction", 6000, 100, apiVersions);
Sender sender = new Sender(logContext, client, metadata, this.accumulator, false, MAX_REQUEST_SIZE, ACKS_ALL, maxRetries, senderMetrics, time, REQUEST_TIMEOUT, RETRY_BACKOFF_MS, txnManager, apiVersions);
ProducerIdAndEpoch producerIdAndEpoch = new ProducerIdAndEpoch(123456L, (short) 0);
TopicPartition tp = new TopicPartition("testForceShutdownWithIncompleteTransaction", 1);
setupWithTransactionState(txnManager);
doInitTransactions(txnManager, producerIdAndEpoch);
txnManager.beginTransaction();
txnManager.maybeAddPartition(tp);
client.prepareResponse(new AddPartitionsToTxnResponse(0, Collections.singletonMap(tp, Errors.NONE)));
sender.runOnce();
// Try to commit the transaction but it won't happen as we'll forcefully close the sender
TransactionalRequestResult commitResult = txnManager.beginCommit();
sender.forceClose();
sender.run();
assertThrows(KafkaException.class, commitResult::await, "The test expected to throw a KafkaException for forcefully closing the sender");
} finally {
m.close();
}
}
Aggregations