projects
/
xudocci.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
2769f52
)
Fix waiting for connections.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 13 Jan 2015 21:24:31 +0000
(22:24 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 13 Jan 2015 21:24:31 +0000
(22:24 +0100)
src/main/java/net/pterodactylus/xdcc/core/ConnectionBackoff.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/xdcc/core/Core.java
patch
|
blob
|
history
src/test/java/net/pterodactylus/xdcc/core/ConnectionBackoffTest.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/xdcc/core/ConnectionBackoff.java
b/src/main/java/net/pterodactylus/xdcc/core/ConnectionBackoff.java
index
5ba44a6
..
e0f9509
100644
(file)
--- a/
src/main/java/net/pterodactylus/xdcc/core/ConnectionBackoff.java
+++ b/
src/main/java/net/pterodactylus/xdcc/core/ConnectionBackoff.java
@@
-62,6
+62,10
@@
public class ConnectionBackoff {
return connectionFailureCounter;
}
return connectionFailureCounter;
}
+ public long getConnectionTime(Network network) {
+ return Instant.now(clock).toEpochMilli() + getBackoff(network);
+ }
+
private class ConnectionFailureCounter {
private final Object lock = new Object();
private class ConnectionFailureCounter {
private final Object lock = new Object();
diff --git
a/src/main/java/net/pterodactylus/xdcc/core/Core.java
b/src/main/java/net/pterodactylus/xdcc/core/Core.java
index
b020c1a
..
00d1fbd
100644
(file)
--- a/
src/main/java/net/pterodactylus/xdcc/core/Core.java
+++ b/
src/main/java/net/pterodactylus/xdcc/core/Core.java
@@
-428,17
+428,17
@@
public class Core extends AbstractExecutionThreadService {
}
Map<Long, Network> timesForNextConnects = new TreeMap<>(missingNetworks.stream()
}
Map<Long, Network> timesForNextConnects = new TreeMap<>(missingNetworks.stream()
- .collect(Collectors.toMap(connectionBackoff::get
Backoff
, Function.identity(), (network, ignore) -> network)));
+ .collect(Collectors.toMap(connectionBackoff::get
ConnectionTime
, Function.identity(), (network, ignore) -> network)));
Optional<Entry<Long, Network>> firstNetwork = Optional.fromNullable(timesForNextConnects.entrySet().stream().findFirst().orElse(null));
if (!firstNetwork.isPresent()) {
continue;
}
Optional<Entry<Long, Network>> firstNetwork = Optional.fromNullable(timesForNextConnects.entrySet().stream().findFirst().orElse(null));
if (!firstNetwork.isPresent()) {
continue;
}
- if (firstNetwork.get().getKey() >
0
) {
- eventBus.post(new GenericMessage(String.format("Waiting %d minutes to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.get().getKey()), firstNetwork.get().getValue().name())));
+ if (firstNetwork.get().getKey() >
System.currentTimeMillis()
) {
+ eventBus.post(new GenericMessage(String.format("Waiting %d minutes to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.get().getKey()
- System.currentTimeMillis()
), firstNetwork.get().getValue().name())));
synchronized (syncObject) {
try {
synchronized (syncObject) {
try {
- syncObject.wait(firstNetwork.get().getKey());
+ syncObject.wait(firstNetwork.get().getKey()
- System.currentTimeMillis()
);
} catch (InterruptedException ie1) {
/* ignore. */
}
} catch (InterruptedException ie1) {
/* ignore. */
}
@@
-446,6
+446,9
@@
public class Core extends AbstractExecutionThreadService {
if (!isRunning()) {
break;
}
if (!isRunning()) {
break;
}
+ if (firstNetwork.get().getKey() > System.currentTimeMillis()) {
+ continue;
+ }
}
connectNetwork(firstNetwork.get().getValue());
}
connectNetwork(firstNetwork.get().getValue());
diff --git
a/src/test/java/net/pterodactylus/xdcc/core/ConnectionBackoffTest.java
b/src/test/java/net/pterodactylus/xdcc/core/ConnectionBackoffTest.java
index
adaae8b
..
91b1c82
100644
(file)
--- a/
src/test/java/net/pterodactylus/xdcc/core/ConnectionBackoffTest.java
+++ b/
src/test/java/net/pterodactylus/xdcc/core/ConnectionBackoffTest.java
@@
-17,7
+17,8
@@
import org.mockito.Mockito;
public class ConnectionBackoffTest {
private final Network network = Mockito.mock(Network.class);
public class ConnectionBackoffTest {
private final Network network = Mockito.mock(Network.class);
- private final Clock fixedClock = Clock.fixed(Instant.now(), ZoneId.systemDefault());
+ private final Instant now = Instant.now();
+ private final Clock fixedClock = Clock.fixed(now, ZoneId.systemDefault());
private final ConnectionBackoff connectionBackoff = new ConnectionBackoff(fixedClock);
@Test
private final ConnectionBackoff connectionBackoff = new ConnectionBackoff(fixedClock);
@Test
@@
-28,12
+29,14
@@
public class ConnectionBackoffTest {
@Test
public void firstConnectionIsImmediatelyPossible() {
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(0L));
@Test
public void firstConnectionIsImmediatelyPossible() {
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(0L));
+ MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli()));
}
@Test
public void afterTheFirstFailedConnectionBackoffIsOneMinute() {
connectionBackoff.connectionFailed(network);
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(60000L));
}
@Test
public void afterTheFirstFailedConnectionBackoffIsOneMinute() {
connectionBackoff.connectionFailed(network);
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(60000L));
+ MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli() + 60000));
}
@Test
}
@Test
@@
-41,6
+44,7
@@
public class ConnectionBackoffTest {
connectionBackoff.connectionFailed(network);
connectionBackoff.connectionFailed(network);
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(72000L));
connectionBackoff.connectionFailed(network);
connectionBackoff.connectionFailed(network);
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(72000L));
+ MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli() + 72000));
}
@Test
}
@Test
@@
-48,6
+52,7
@@
public class ConnectionBackoffTest {
connectionBackoff.connectionFailed(network);
connectionBackoff.connectionSuccessful(network);
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(0L));
connectionBackoff.connectionFailed(network);
connectionBackoff.connectionSuccessful(network);
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(0L));
+ MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli()));
}
@Test
}
@Test
@@
-56,6
+61,7
@@
public class ConnectionBackoffTest {
connectionBackoff.connectionFailed(network);
}
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(3600000L));
connectionBackoff.connectionFailed(network);
}
MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(3600000L));
+ MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli() + 3600000));
}
}
}
}