mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Merge branch '4.2'
This commit is contained in:
commit
7a5f9e6a03
187 changed files with 2284 additions and 588 deletions
|
@ -537,7 +537,7 @@ public class SmackIntegrationTestFramework {
|
|||
throw new IllegalStateException();
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(accountUsername)) {
|
||||
accountUsername = USERNAME_PREFIX + '-' + middlefix + '-' +testRunResult.testRunId;
|
||||
accountUsername = USERNAME_PREFIX + '-' + middlefix + '-' + testRunResult.testRunId;
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(accountPassword)) {
|
||||
accountPassword = StringUtils.insecureRandomString(16);
|
||||
|
|
|
@ -26,7 +26,7 @@ public class ResultSyncPoint<R, E extends Exception> {
|
|||
private E exception;
|
||||
|
||||
public R waitForResult(long timeout) throws E, InterruptedException, TimeoutException {
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ public class ResultSyncPoint<R, E extends Exception> {
|
|||
|
||||
|
||||
public void signal(R result) {
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
this.result = Objects.requireNonNull(result);
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void signal(E exception) {
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
this.exception = Objects.requireNonNull(exception);
|
||||
notifyAll();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
|||
|
||||
public class HttpFileUploadIntegrationTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
private static final int FILE_SIZE = 1024*128;
|
||||
private static final int FILE_SIZE = 1024 * 128;
|
||||
|
||||
private final HttpFileUploadManager hfumOne;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015 Florian Schmaus
|
||||
* Copyright 2015-2017 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,10 +18,23 @@ package org.jivesoftware.smackx.ping;
|
|||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public class PingIntegrationTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
|
@ -35,4 +48,52 @@ public class PingIntegrationTest extends AbstractSmackIntegrationTest {
|
|||
assertTrue(pingManager.pingMyServer());
|
||||
}
|
||||
|
||||
private static final class Pinger implements Runnable {
|
||||
private final List<Jid> toPing;
|
||||
private final Collection<Future<Boolean>> pongFutures;
|
||||
|
||||
private final PingManager pingManager;
|
||||
|
||||
private Pinger(XMPPConnection connection, Collection<Future<Boolean>> pongFutures, Jid... toPing) {
|
||||
this(connection, pongFutures, Arrays.asList(toPing));
|
||||
}
|
||||
|
||||
private Pinger(XMPPConnection connection, Collection<Future<Boolean>> pongFutures, List<Jid> toPing) {
|
||||
this.toPing = toPing;
|
||||
this.pongFutures = pongFutures;
|
||||
|
||||
this.pingManager = PingManager.getInstanceFor(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<Future<Boolean>> futures = new ArrayList<>();
|
||||
for (Jid jid : toPing) {
|
||||
Future<Boolean> future = pingManager.pingAsync(jid);
|
||||
futures.add(future);
|
||||
}
|
||||
pongFutures.addAll(futures);
|
||||
}
|
||||
}
|
||||
|
||||
@SmackIntegrationTest
|
||||
public void pingAsync() throws InterruptedException, ExecutionException {
|
||||
List<Future<Boolean>> pongFutures = Collections.synchronizedList(new ArrayList<Future<Boolean>>());
|
||||
Runnable[] pinger = new Runnable[3];
|
||||
pinger[0] = new Pinger(conOne, pongFutures, conTwo.getUser(), conThree.getUser());
|
||||
pinger[1] = new Pinger(conTwo, pongFutures, conOne.getUser(), conThree.getUser());
|
||||
pinger[2] = new Pinger(conThree, pongFutures, conOne.getUser(), conTwo.getUser());
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(pinger.length);
|
||||
for (Runnable runnable : pinger) {
|
||||
executorService.execute(runnable);
|
||||
}
|
||||
|
||||
executorService.shutdown();
|
||||
executorService.awaitTermination(1, TimeUnit.MINUTES);
|
||||
|
||||
for (Future<Boolean> pongFuture : pongFutures) {
|
||||
assertTrue(pongFuture.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public class FormTest extends AbstractSmackIntegrationTest {
|
|||
chat.sendMessage(msg);
|
||||
|
||||
// Get the message with the form to fill out
|
||||
Message msg2 = (Message)collector2.nextResult();
|
||||
Message msg2 = (Message) collector2.nextResult();
|
||||
assertNotNull("Messge not found", msg2);
|
||||
// Retrieve the form to fill out
|
||||
Form formToRespond = Form.getFormFrom(msg2);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ResultSyncPointTest {
|
|||
assertEquals(result, receivedResult);
|
||||
}
|
||||
|
||||
@Test(expected=TestException.class)
|
||||
@Test(expected = TestException.class)
|
||||
public void exceptionTestResultSyncPoint() throws InterruptedException, TimeoutException, Exception {
|
||||
final CyclicBarrier barrier = new CyclicBarrier(2);
|
||||
final ResultSyncPoint<String, TestException> rsp = new ResultSyncPoint<>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue