mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
More tests
This commit is contained in:
parent
85f3221a60
commit
9f22cef175
@ -6,8 +6,7 @@ public enum FlatFileDataFlag {
|
|||||||
MISSING_NAME,
|
MISSING_NAME,
|
||||||
DUPLICATE_NAME,
|
DUPLICATE_NAME,
|
||||||
DUPLICATE_UUID,
|
DUPLICATE_UUID,
|
||||||
BAD_UUID_DATA, //Can be because it is missing, null, or just not compatible data
|
BAD_UUID_DATA, //Can be because it is missing, null, or corrupted or some other reason
|
||||||
TOO_INCOMPLETE,
|
TOO_INCOMPLETE,
|
||||||
JUNK,
|
CORRUPTED_OR_UNRECOGNIZABLE,
|
||||||
EMPTY_LINE,
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class FlatFileDataProcessor {
|
|||||||
private final @NotNull Logger logger;
|
private final @NotNull Logger logger;
|
||||||
private final HashSet<String> names;
|
private final HashSet<String> names;
|
||||||
private final HashSet<UUID> uuids;
|
private final HashSet<UUID> uuids;
|
||||||
private int uniqueProcessingID;
|
private int uniqueProcessingID; //TODO: Not being used, should we use it?
|
||||||
boolean corruptDataFound;
|
boolean corruptDataFound;
|
||||||
|
|
||||||
public FlatFileDataProcessor(@NotNull Logger logger) {
|
public FlatFileDataProcessor(@NotNull Logger logger) {
|
||||||
@ -55,7 +55,7 @@ public class FlatFileDataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Flag as junk (corrupt)
|
//Flag as junk (corrupt)
|
||||||
builder.appendFlag(FlatFileDataFlag.JUNK);
|
builder.appendFlag(FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE);
|
||||||
|
|
||||||
//TODO: This block here is probably pointless
|
//TODO: This block here is probably pointless
|
||||||
if(splitDataLine.length >= 10 //The value here is kind of arbitrary, it shouldn't be too low to avoid false positives, but also we aren't really going to correctly identify when player data has been corrupted or not with 100% accuracy ever
|
if(splitDataLine.length >= 10 //The value here is kind of arbitrary, it shouldn't be too low to avoid false positives, but also we aren't really going to correctly identify when player data has been corrupted or not with 100% accuracy ever
|
||||||
@ -67,7 +67,7 @@ public class FlatFileDataProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerData(builder.appendFlag(FlatFileDataFlag.JUNK));
|
registerData(builder.appendFlag(FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,20 +123,8 @@ public class FlatFileDataProcessor {
|
|||||||
if(!name.isEmpty())
|
if(!name.isEmpty())
|
||||||
names.add(name);
|
names.add(name);
|
||||||
|
|
||||||
//Make sure the data is up to date schema wise
|
//Make sure the data is up to date schema wise, if it isn't we adjust it to the correct size and flag it for repair
|
||||||
if(splitDataLine.length < DATA_ENTRY_COUNT) {
|
splitDataLine = isDataSchemaUpToDate(splitDataLine, builder, badDataValues);
|
||||||
int oldLength = splitDataLine.length;
|
|
||||||
splitDataLine = Arrays.copyOf(splitDataLine, DATA_ENTRY_COUNT);
|
|
||||||
int newLength = splitDataLine.length;
|
|
||||||
|
|
||||||
//TODO: Test this
|
|
||||||
for(int i = oldLength; i < (newLength - 1); i++){
|
|
||||||
badDataValues[i] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.appendFlag(FlatFileDataFlag.INCOMPLETE);
|
|
||||||
builder.setSplitStringData(splitDataLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* After establishing this data has at least an identity we check for bad data
|
* After establishing this data has at least an identity we check for bad data
|
||||||
@ -169,6 +157,26 @@ public class FlatFileDataProcessor {
|
|||||||
registerData(builder);
|
registerData(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull String[] isDataSchemaUpToDate(@NotNull String[] splitDataLine, @NotNull FlatFileDataBuilder builder, boolean[] badDataValues) {
|
||||||
|
assert splitDataLine.length <= DATA_ENTRY_COUNT; //should NEVER be higher
|
||||||
|
|
||||||
|
if(splitDataLine.length < DATA_ENTRY_COUNT) {
|
||||||
|
int oldLength = splitDataLine.length;
|
||||||
|
splitDataLine = Arrays.copyOf(splitDataLine, DATA_ENTRY_COUNT);
|
||||||
|
int newLength = splitDataLine.length;
|
||||||
|
|
||||||
|
//TODO: Test this
|
||||||
|
for(int i = oldLength; i < (newLength - 1); i++){
|
||||||
|
badDataValues[i] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.appendFlag(FlatFileDataFlag.INCOMPLETE);
|
||||||
|
builder.setSplitStringData(splitDataLine);
|
||||||
|
}
|
||||||
|
return splitDataLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean shouldNotBeEmpty(String data, int index) {
|
public boolean shouldNotBeEmpty(String data, int index) {
|
||||||
if(getExpectedValueType(index) == ExpectedType.IGNORED) {
|
if(getExpectedValueType(index) == ExpectedType.IGNORED) {
|
||||||
return false;
|
return false;
|
||||||
@ -221,8 +229,9 @@ public class FlatFileDataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reportBadDataLine(String warning, String context, String dataLine) {
|
private void reportBadDataLine(String warning, String context, String dataLine) {
|
||||||
logger.severe("FlatFileDatabaseBuilder Warning: " + warning + " - " + context);
|
logger.warning("FlatFileDatabaseBuilder Warning: " + warning + " - " + context);
|
||||||
logger.severe("FlatFileDatabaseBuilder: (Line Data) - " + dataLine);
|
logger.warning("FlatFileDatabaseBuilder: (Line Data) - " + dataLine);
|
||||||
|
logger.warning("mcMMO will repair this data if automatically (if it is possible).");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMinimumSplitDataLength() {
|
private int getMinimumSplitDataLength() {
|
||||||
@ -237,7 +246,7 @@ public class FlatFileDataProcessor {
|
|||||||
flatFileDataFlags.addAll(flatFileDataContainer.getDataFlags());
|
flatFileDataFlags.addAll(flatFileDataContainer.getDataFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ExpectedType getExpectedValueType(int dataIndex) throws IndexOutOfBoundsException {
|
public static @NotNull ExpectedType getExpectedValueType(int dataIndex) throws IndexOutOfBoundsException {
|
||||||
switch(dataIndex) {
|
switch(dataIndex) {
|
||||||
case USERNAME_INDEX:
|
case USERNAME_INDEX:
|
||||||
return ExpectedType.STRING;
|
return ExpectedType.STRING;
|
||||||
@ -316,6 +325,8 @@ public class FlatFileDataProcessor {
|
|||||||
if(splitData == null)
|
if(splitData == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//We add a trailing : as it is needed for some reason (is it?)
|
||||||
|
//TODO: Is the trailing ":" actually necessary?
|
||||||
String fromSplit = org.apache.commons.lang.StringUtils.join(splitData, ":") + ":";
|
String fromSplit = org.apache.commons.lang.StringUtils.join(splitData, ":") + ":";
|
||||||
stringBuilder.append(fromSplit).append("\r\n");
|
stringBuilder.append(fromSplit).append("\r\n");
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public class CategorizedFlatFileData implements FlatFileDataContainer {
|
|||||||
private final @NotNull String[] splitData;
|
private final @NotNull String[] splitData;
|
||||||
private final int uniqueProcessingId;
|
private final int uniqueProcessingId;
|
||||||
|
|
||||||
protected CategorizedFlatFileData(int uniqueProcessingId, @NotNull HashSet<FlatFileDataFlag> dataFlags, @NotNull String[] splitData) {
|
public CategorizedFlatFileData(int uniqueProcessingId, @NotNull HashSet<FlatFileDataFlag> dataFlags, @NotNull String[] splitData) {
|
||||||
this.uniqueProcessingId = uniqueProcessingId;
|
this.uniqueProcessingId = uniqueProcessingId;
|
||||||
this.dataFlags = dataFlags;
|
this.dataFlags = dataFlags;
|
||||||
this.splitData = splitData;
|
this.splitData = splitData;
|
||||||
|
@ -6,7 +6,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import static com.gmail.nossr50.database.FlatFileDatabaseManager.*;
|
import static com.gmail.nossr50.database.FlatFileDatabaseManager.*;
|
||||||
import static com.gmail.nossr50.database.FlatFileDatabaseManager.UUID_INDEX;
|
|
||||||
|
|
||||||
public class FlatFileSaveDataProcessor {
|
public class FlatFileSaveDataProcessor {
|
||||||
|
|
||||||
@ -18,11 +17,10 @@ public class FlatFileSaveDataProcessor {
|
|||||||
//Data of this type is not salvageable
|
//Data of this type is not salvageable
|
||||||
//TODO: Test that we ignore the things we are supposed to ignore
|
//TODO: Test that we ignore the things we are supposed to ignore
|
||||||
//TODO: Should we even keep track of the bad data or just not even build data containers for it? Making containers for it is only really useful for debugging.. well I suppose operations are typically async so it shouldn't matter
|
//TODO: Should we even keep track of the bad data or just not even build data containers for it? Making containers for it is only really useful for debugging.. well I suppose operations are typically async so it shouldn't matter
|
||||||
if(dataContainer.getDataFlags().contains(FlatFileDataFlag.JUNK)
|
if(dataContainer.getDataFlags().contains(FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE)
|
||||||
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.DUPLICATE_UUID) //For now we will not try to fix any issues with UUIDs
|
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.DUPLICATE_UUID) //For now we will not try to fix any issues with UUIDs
|
||||||
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.BAD_UUID_DATA) //For now we will not try to fix any issues with UUIDs
|
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.BAD_UUID_DATA) //For now we will not try to fix any issues with UUIDs
|
||||||
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.TOO_INCOMPLETE)
|
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.TOO_INCOMPLETE)) {
|
||||||
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.EMPTY_LINE)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.gmail.nossr50.database;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FlatFileDataProcessorTest {
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
@Test
|
||||||
|
public void testGetExpectedValueType() {
|
||||||
|
for(int i = 0; i < FlatFileDatabaseManager.DATA_ENTRY_COUNT; i++) {
|
||||||
|
FlatFileDataProcessor.getExpectedValueType(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
@Test(expected = IndexOutOfBoundsException.class)
|
||||||
|
public void testGetExpectedValueTypeException() {
|
||||||
|
for(int i = 0; i < FlatFileDatabaseManager.DATA_ENTRY_COUNT+1; i++) {
|
||||||
|
FlatFileDataProcessor.getExpectedValueType(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -131,7 +131,7 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindCorruptData() {
|
public void testFindCorruptData() {
|
||||||
overwriteDataAndCheckForFlag(db, corruptDatabaseData, FlatFileDataFlag.JUNK);
|
overwriteDataAndCheckForFlag(db, corruptDatabaseData, FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -139,11 +139,6 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
overwriteDataAndCheckForFlag(db, emptyNameDatabaseData, FlatFileDataFlag.MISSING_NAME);
|
overwriteDataAndCheckForFlag(db, emptyNameDatabaseData, FlatFileDataFlag.MISSING_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void testFindEmptyLine() {
|
|
||||||
// overwriteDataAndCheckForFlag(db, emptyLineDatabaseData, FlatFileDataFlag.EMPTY_LINE);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindBadValues() {
|
public void testFindBadValues() {
|
||||||
overwriteDataAndCheckForFlag(db, badDatabaseData, FlatFileDataFlag.BAD_VALUES);
|
overwriteDataAndCheckForFlag(db, badDatabaseData, FlatFileDataFlag.BAD_VALUES);
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.gmail.nossr50.database.flatfile;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.database.FlatFileDatabaseManager;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class FlatFileSaveDataProcessorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPreparedSaveDataLine() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void repairBadData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getZeroInitialisedData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AssertionError.class)
|
||||||
|
public void testTooManyDataEntriesSplitString() {
|
||||||
|
FlatFileDataContainer dataContainer = new CategorizedFlatFileData(0, new HashSet<>(), new String[FlatFileDatabaseManager.DATA_ENTRY_COUNT + 1]);
|
||||||
|
FlatFileSaveDataProcessor.getPreparedSaveDataLine(dataContainer);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user