mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
Fix same server check logging warning every 30 min
This commit is contained in:
parent
c1f08cbc99
commit
3b40188bf5
@ -66,9 +66,10 @@ public class TPSStoreTransaction extends Transaction {
|
||||
}
|
||||
|
||||
private void performDuplicateServerUUIDServerCheck(long now) {
|
||||
Long lastStoredData = query(TPSQueries.fetchLastStoredTpsDate(serverUUID)).orElse(0L);
|
||||
Long lastStoredData = query(TPSQueries.fetchLastStoredTpsDate(serverUUID))
|
||||
.orElse(0L);
|
||||
long diff = now - lastStoredData;
|
||||
if (logger != null && diff > TimeUnit.SECONDS.toMillis(30)) {
|
||||
if (logger != null && diff < TimeUnit.SECONDS.toMillis(30)) {
|
||||
logger.warn("Database had TPS data which was stored " + diff + "ms ago, this is a sign that two servers are storing data as " + serverUUID +
|
||||
" - Check that you have not copied /plugins/Plan/ServerInfoFile.yml between two servers. (This warning will show on both servers)");
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import utilities.RandomData;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -78,12 +79,33 @@ public interface TPSQueriesTest extends DatabaseTestPreparer {
|
||||
assertEquals(expected, actual, () -> "Wrong return value. " + Lists.map(tpsData, TPS::getPlayers).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
default void maxDateIsFetched() {
|
||||
List<TPS> tpsData = RandomData.randomTPS();
|
||||
|
||||
for (TPS tps : tpsData) {
|
||||
db().executeTransaction(new TPSStoreTransaction(serverUUID(), tps));
|
||||
}
|
||||
|
||||
long expected = tpsData.stream()
|
||||
.mapToLong(TPS::getDate)
|
||||
.max()
|
||||
.orElseThrow(AssertionError::new);
|
||||
long result = db().query(TPSQueries.fetchLastStoredTpsDate(serverUUID()))
|
||||
.orElseThrow(AssertionError::new);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
default void sameServerIsDetected() {
|
||||
TPSStoreTransaction.setLastStorageCheck(0L);
|
||||
TPS tps = RandomData.randomTPS().get(0);
|
||||
int value = ThreadLocalRandom.current().nextInt();
|
||||
long time = System.currentTimeMillis() - 50;
|
||||
TPS tps = new TPS(time, time, value, time, time, value, value, time);
|
||||
PluginLogger logger = Mockito.mock(PluginLogger.class);
|
||||
db().executeTransaction(new TPSStoreTransaction(logger, serverUUID(), tps));
|
||||
|
||||
TPSStoreTransaction.setLastStorageCheck(0L);
|
||||
|
||||
db().executeTransaction(new TPSStoreTransaction(logger, serverUUID(), tps));
|
||||
db().executeTransaction(new TPSStoreTransaction(logger, serverUUID(), tps));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user