mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 19:51:25 +01:00
Periodic DBCommit task. Removed remaints of KillData victimID
This commit is contained in:
parent
8e2e710f98
commit
af63e3cb92
@ -22,6 +22,7 @@ public class DBCommitProcessor extends Processor<Database> {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
// TODO Prevent Commit during batch operations.
|
||||
try {
|
||||
object.commit();
|
||||
} catch (SQLException e) {
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.handling.DBCommitProcessor;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
|
||||
/**
|
||||
* Periodically commits changes to the SQLite Database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PeriodicDBCommitTask extends AbsRunnable {
|
||||
|
||||
private Plan plugin;
|
||||
|
||||
public PeriodicDBCommitTask(Plan plugin) {
|
||||
super("PeriodicDBCommitTask");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Database db = plugin.getDB();
|
||||
if ("mysql".equals(db.getConfigName())) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
plugin.addToProcessQueue(new DBCommitProcessor(db));
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -17,20 +18,27 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class KillDataTest {
|
||||
|
||||
private KillData test;
|
||||
private UUID testUUID;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public KillDataTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testUUID = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
|
||||
test = new KillData(testUUID, "TestWeapon", 100L);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetVictim() {
|
||||
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
|
||||
KillData k = new KillData(uuid, 1, "TestWeapon", 100L);
|
||||
assertEquals(k.getVictim(), uuid);
|
||||
assertEquals(test.getVictim(), testUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,9 +46,7 @@ public class KillDataTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetDate() {
|
||||
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
|
||||
KillData k = new KillData(uuid, 1, "TestWeapon", 100L);
|
||||
assertEquals(k.getDate(), 100L);
|
||||
assertEquals(test.getDate(), 100L);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,19 +54,6 @@ public class KillDataTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetWeapon() {
|
||||
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
|
||||
KillData k = new KillData(uuid, 1, "TestWeapon", 100L);
|
||||
assertEquals(k.getWeapon(), "TestWeapon");
|
||||
assertEquals(test.getWeapon(), "TestWeapon");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetVictimUserID() {
|
||||
UUID uuid = UUID.fromString("71cfb6f0-c3ef-4954-8abe-13fa07afc340");
|
||||
KillData k = new KillData(uuid, 1, "TestWeapon", 100L);
|
||||
assertEquals(k.getVictimUserID(), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,14 @@ public class DatabaseCommitTest {
|
||||
assertTrue("Errors were caught.", rows == rowsAgain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExceptionWhenCommitEmpty() throws SQLException {
|
||||
db.init();
|
||||
db.commit();
|
||||
db.commit();
|
||||
db.commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile() throws SQLException {
|
||||
db.init();
|
||||
|
Loading…
Reference in New Issue
Block a user