v0.4 stabilization

This commit is contained in:
Dmitry Isaenko 2019-01-25 06:44:06 +03:00
parent c8ab5a0964
commit 9de9f8d36f
11 changed files with 371 additions and 145 deletions

View file

@ -23,6 +23,7 @@ Source code spreads under the GNU General Public License v3 or higher. Please se
Used libraries:
* GSON: https://github.com/google/gson
* sqliteJDBC: https://bitbucket.org/xerial/sqlite-jdbc
* mongodb-driver-sync: https://mongodb.github.io/mongo-java-driver/3.9/
## TODO:

View file

@ -22,18 +22,17 @@ public class BotDriver {
}
public static synchronized Worker getWorker(String serverName, String chanelName){
if (serverDriver.containsKey(serverName)) {
switch (serverDriver.get(serverName)[0][0]) {
case "Files":
return new BotFilesWorker(serverName, serverDriver.get(serverName)[1], chanelName);
case "SQLite":
return new BotSQLiteWorker(serverName, serverDriver.get(serverName)[1], chanelName);
case "MongoDB":
switch (serverDriver.get(serverName)[0][0].toLowerCase()) {
case "files":
BotFilesWorker botFilesWorker = new BotFilesWorker(serverName, serverDriver.get(serverName)[1], chanelName);
return validateConstancy(botFilesWorker, serverName, chanelName);
case "sqlite":
BotSQLiteWorker botSQLiteWorker = new BotSQLiteWorker(serverName, serverDriver.get(serverName)[1], chanelName);
return validateConstancy(botSQLiteWorker, serverName, chanelName);
case "mongodb":
BotMongoWorker botMongoWorker = new BotMongoWorker(serverName, serverDriver.get(serverName)[1], chanelName);
if (botMongoWorker.isConsistent())
return botMongoWorker;
else
System.out.println("BotDriver: Unable to use MongoWorker for "+serverName+". Using ZeroWorker instead."); // else, fall down and use BotZeroWorker.
case "Zero":
return validateConstancy(botMongoWorker, serverName, chanelName);
case "zero":
return new BotZeroWorker();
default:
System.out.println("Configuration issue: BotDriver->getWorker() can't find required driver \""
@ -44,4 +43,13 @@ public class BotDriver {
}
return null;
}
private static Worker validateConstancy(Worker worker, String srv, String chan){ // synchronized?
if (worker.isConsistent()){
return worker;
}
else {
System.out.println("BotDriver: Unable to use "+worker.getClass().getSimpleName()+" for "+srv+"/"+chan+". Using ZeroWorker instead.");
return new BotZeroWorker();
}
}
}

View file

@ -16,31 +16,35 @@ public class BotFilesWorker implements Worker {
private LocalDate fileWriterDay;
private FileWriter fileWriter;
public BotFilesWorker(String server, String[] driverParameters, String channel){
if (System.getProperty("os.name").startsWith("Windows")){
channel = channel.replaceAll("\",",",");
}
else {
channel = channel.replaceAll("/",",");
}
private String ircServer; // hold for debug only
driverParameters[0] = driverParameters[0].trim(); //Consider parameters[0] as dirLocation
String dirLocation;
if (driverParameters[0].endsWith(File.separator))
dirLocation = driverParameters[0]+server;
public BotFilesWorker(String server, String[] driverParameters, String channel){
ircServer = server;
dateFormat = DateTimeFormatter.ofPattern("HH:mm:ss");
channel = channel.replaceAll(File.separator, ",");
String dirLocation = driverParameters[0].trim();
if (dirLocation.endsWith(File.separator))
dirLocation = dirLocation+server;
else
dirLocation = driverParameters[0]+File.separator+server;
File dir = new File(dirLocation);
dir.mkdirs();
if (!dir.exists()) {
System.out.println("Unable to create directory to store files: " + dirLocation); //TODO: notify requester
this.consistent = false;
}
dirLocation = dirLocation+File.separator+server;
this.filePath = dirLocation+File.separator+channel;
dateFormat = DateTimeFormatter.ofPattern("HH:mm:ss");
if (resetFileWriter(false))
this.consistent = true;
File dir = new File(dirLocation);
try {
dir.mkdirs(); // ignore result, because if it's already exists we're good. Otherwise, it will be created. Only issue that can occur is SecurityException thrown, so let's catch it.
} catch (Exception e){
System.out.println("BotFilesWorker (@"+server+")->constructor(): Failure:\n\tUnable to create directory to store DB file: \n\t" +e);
return; // consistent = false;
}
if (!dir.exists()) {
System.out.println("BotFilesWorker (@"+server+")->constructor() failed:\n\tUnable to create directory to store files: " + dirLocation); //TODO: notify requester
return;
}
this.consistent = resetFileWriter(false);
}
private boolean resetFileWriter(boolean reassign){
@ -52,7 +56,7 @@ public class BotFilesWorker implements Worker {
return true;
}
catch (java.io.IOException e){
System.out.println("Internal issue: BotFilesWorker->constructor() can't create file to store logs: "+this.filePath);
System.out.println("BotFilesWorker (@"+ircServer+")->resetFileWriter() failed:\n\tCan't create file to store logs: "+this.filePath);
return false;
}
}
@ -66,7 +70,7 @@ public class BotFilesWorker implements Worker {
* argument[1] should be always 'subject'
* */
@Override
public void logAdd(String event, String initiatorArg, String messageArg) {
public boolean logAdd(String event, String initiatorArg, String messageArg) {
switch (event){
case "PRIVMSG":
PRIVMSG(initiatorArg, messageArg);
@ -96,27 +100,31 @@ public class BotFilesWorker implements Worker {
this.prettyPrint("["+LocalTime.now().format(dateFormat)+"] "+event+" "+initiatorArg+" "+messageArg+"\n"); // TODO: QA @ big data
break;
}
}
@Override
public void close() {
try {
fileWriter.close();
}
catch (java.io.IOException e){
System.out.println("Internal issue: BotFilesWorker->close() failed\n\tUnable to properly close file: "+this.filePath); // Live with it.
}
return consistent;
}
private void prettyPrint(String string){
if (LocalDate.now().isAfter(fileWriterDay))
resetFileWriter(true);
//if (consistent) { // could be not-opened
try {
if (LocalDate.now().isAfter(fileWriterDay)) {
if (!resetFileWriter(true)) {
this.close(); // Error message already printed
return;
}
}
fileWriter.write(string);
fileWriter.flush();
} catch (IOException e) {
System.out.println("Internal issue: BotFilesWorker->prettyPrint() failed\n\tUnable to write logs of "+this.filePath+" because of internal failure in LocalTime representation.");
System.out.println("BotFilesWorker (@" + ircServer + ")->prettyPrint() failed\n\tUnable to write logs of " + this.filePath + " because of internal failure in LocalTime representation.");
this.close();
//consistent = false;
} catch (NullPointerException npe){
System.out.println("BotFilesWorker (@" + ircServer + ")->prettyPrint() failed\n\tUnable to write logs of " + this.filePath + " because file descriptor already closed/was not opened.");
consistent = false;
} catch (Exception unknowne){ // ??? No ideas. Just in case. Consider removing.
System.out.println("BotFilesWorker (@" + ircServer + ")->prettyPrint() failed\n\tUnable to write logs of " + this.filePath + " because of exception:\n\t"+unknowne);
this.close();
}
//}
}
private String genDate(){
return "["+LocalTime.now().format(dateFormat)+"] ";
@ -160,4 +168,16 @@ public class BotFilesWorker implements Worker {
private void TOPIC(String initiatorArg, String messageArg) {
this.prettyPrint(genDate()+"-!- "+getUserNameAndHost(initiatorArg)+"has changed topic to: "+messageArg.replaceAll("^.+?:", "")+"\n");
}
@Override
public void close() {
try {
if (fileWriter !=null)
fileWriter.close();
}
catch (java.io.IOException e){
System.out.println("BotFilesWorker (@"+ircServer+")->close() failed\n\tUnable to properly close file: "+this.filePath); // Live with it.
}
this.consistent = false;
}
}

View file

@ -11,17 +11,19 @@ import org.bson.Document;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/** For each IRC server we create one DB that stored in the hashmap ('static', since we may have few configuration that have to work at once)
* For each channel we store collection that have name of the ircServer + chanelName.
* If user decides to use one MongoDB for various servers, he may use even one DB (declared in configuration file) and store collections in there.
* **/
public class BotMongoWorker implements Worker {
public class BotMongoWorker implements Worker { //TODO consider skipping checks if server already added.
private static Map<String, MongoClient> serversMap = Collections.synchronizedMap(new HashMap<String, MongoClient>());
private String ircServer;
private MongoCollection<Document> collection;
private boolean consistent = false; // TODO: clarify possible issues???
private boolean consistent = false;
private boolean isItSystemThread = false;
@ -85,7 +87,6 @@ public class BotMongoWorker implements Worker {
@Override
public void serverDescriptionChanged(ServerDescriptionChangedEvent serverDescriptionChangedEvent) {
if (!serverDescriptionChangedEvent.getNewDescription().isOk()) {
consistent = false;
close(ircServer); // ircServer recieved by constructor, not this.ircServer
System.out.println("BotMongoWorker (@"+ircServer+"): ServerListener: Server description changed (exception occurs): "
+ serverDescriptionChangedEvent.getNewDescription().getException());
@ -96,6 +97,7 @@ public class BotMongoWorker implements Worker {
MongoClientSettings MCS = MongoClientSettings.builder()
// .addCommandListener(mongoCommandListener)
.applyConnectionString(new ConnectionString("mongodb://"+mongoHostAddr))
.applyToClusterSettings(builder -> builder.serverSelectionTimeout(5, TimeUnit.SECONDS))
.applyToServerSettings(builder -> builder.addServerListener(mongoServerListener))
.credential(MongoCredential.createCredential(mongoUser, mongoDBName, mongoPass.toCharArray()))
.build();
@ -107,30 +109,33 @@ public class BotMongoWorker implements Worker {
MongoDatabase mongoDB = serversMap.get(ircServer).getDatabase(mongoDBName);
collection = mongoDB.getCollection(ircServer + channel);
Document ping = new Document("ping", "1");
Document ping = new Document("ping", 1);
//
try {
collection.insertOne(ping);
consistent = true; // if no exceptions, then true
Document answer = mongoDB.runCommand(ping); // reports to monitor thread if some fuckups happens
if (answer.get("ok") == null || (Double)answer.get("ok") != 1.0d){
close(ircServer);
return;
}
consistent = true;
} catch (MongoCommandException mce){
System.out.println("BotMongoWorker (@"+this.ircServer+"): Command exception. Check if username/password set correctly.");
consistent = false;
close(ircServer); // ircServer received by constructor, not this.ircServer
} catch (MongoTimeoutException mte) {
System.out.println("BotMongoWorker (@"+this.ircServer+"): Timeout exception");
consistent = false;
System.out.println("BotMongoWorker (@"+this.ircServer+"): Timeout exception.");
close(ircServer); // ircServer received by constructor, not this.ircServer
}catch (MongoException me){
System.out.println("BotMongoWorker (@"+this.ircServer+"): MongoDB Exception");
consistent = false;
System.out.println("BotMongoWorker (@"+this.ircServer+"): MongoDB Exception.");
close(ircServer); // ircServer received by constructor, not this.ircServer
} catch (IllegalStateException ise){
System.out.println("BotMongoWorker (@"+this.ircServer+"): Illegal state exception: MongoDB server already closed (not an issue).");
consistent = false;
// no need to close() obviously
}
}
@Override
public void logAdd(String event, String initiatorArg, String messageArg) {
public boolean logAdd(String event, String initiatorArg, String messageArg) {
Document document = new Document("date", getDate())
.append("event", event)
.append("initiator", initiatorArg);
@ -163,7 +168,23 @@ public class BotMongoWorker implements Worker {
//preparedStatement.setString(5,null);
break;
}
collection.insertOne(document); // TODO: try/catch and watch
try {
collection.insertOne(document); // TODO: call finalize?
consistent = true; // if no exceptions, then true
} catch (MongoCommandException mce){
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): Command exception. Check if username/password set correctly.");
this.close();
} catch (MongoTimeoutException mte) {
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): Timeout exception.");
this.close();
}catch (MongoException me){
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): MongoDB Exception.");
this.close();
} catch (IllegalStateException ise){
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): Illegal state exception: MongoDB server already closed (not an issue).");
this.close();
}
return consistent;
}
private long getDate(){ return System.currentTimeMillis() / 1000L; } // UNIX time
@ -178,14 +199,16 @@ public class BotMongoWorker implements Worker {
if (this.isItSystemThread && serversMap.containsKey(ircServer)) {
serversMap.get(ircServer).close();
serversMap.remove(ircServer);
System.out.println("BotMongoWorker (@"+this.ircServer+")->close(): " + ircServer);
//System.out.println("BotMongoWorker (@"+this.ircServer+")->close()"); // expected exit
}
consistent = false;
}
public void close(String server) {
private void close(String server) {
if (serversMap.containsKey(server)) {
serversMap.get(server).close();
serversMap.remove(server);
System.out.println("BotMongoWorker (@"+this.ircServer+")->close(): " + server + " (forced by listeners)");
}
System.out.println("BotMongoWorker (@"+this.ircServer+")->close() [forced by listeners]");
}
consistent = false;
}
}

View file

@ -11,16 +11,24 @@ public class BotSQLiteWorker implements Worker {
private Connection connection;
private boolean consistent = false;
private PreparedStatement preparedStatement;
private String ircServer;
/**
* Don't even think of changing this balalaika.
* */
public BotSQLiteWorker(String server, String[] driverParameters, String channel){ // TODO: threads on SQLite level // remember: One file one DB
this.ircServer = server;
driverParameters[0] = driverParameters[0].trim();
File dir = new File(driverParameters[0]);
dir.mkdirs(); // TODO: Check if not-null
if (!dir.exists()) {
System.out.println("Unable to create directory to store DB file: " + driverParameters[0]); //TODO: notify requester
this.consistent = false;
try {
dir.mkdirs(); // ignore result, because if it's already exists we're good. Otherwise, it will be created. Only issue that can occur is SecurityException thrown, so let's catch it.
} catch (Exception e){
System.out.println("BotSQLiteWorker (@"+server+")->constructor(): Failure:\n\tUnable to create directory to store DB file: \n\t" +e);
return; // consistent = false;
}
if (!dir.exists()) { // probably we might want to try-catch SecurityException, but if it appeared, it has been appeared already in previous block
System.out.println("BotSQLiteWorker (@"+server+")->constructor(): Failure:\n\tUnable to create directory to store DB file: " + driverParameters[0]);
return; // consistent = false;
}
String connectionURL;
if (driverParameters[0].endsWith(File.separator))
@ -28,7 +36,7 @@ public class BotSQLiteWorker implements Worker {
else
connectionURL = "jdbc:sqlite:"+driverParameters[0]+File.separator+server+".db";
String safeChanName = channel.trim().replaceAll("\"","\\\""); // TODO: use trim in every driver/worker?
channel = channel.trim().replaceAll("\"","\\\""); // TODO: use trim in every driver/worker?
try {
SQLiteConfig sqlConfig = new SQLiteConfig();
sqlConfig.setOpenMode(SQLiteOpenMode.NOMUTEX); //SQLITE_OPEN_NOMUTEX : multithreaded mode
@ -37,7 +45,7 @@ public class BotSQLiteWorker implements Worker {
if (connection != null){
// Create table if not created
Statement statement = connection.createStatement();
String query = "CREATE TABLE IF NOT EXISTS \""+safeChanName+"\" ("
String query = "CREATE TABLE IF NOT EXISTS \""+channel+"\" ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ " unixtime INTEGER,"
+ " event TEXT,"
@ -48,7 +56,7 @@ public class BotSQLiteWorker implements Worker {
statement.executeUpdate(query);
// Check table representation
ResultSet rs = statement.executeQuery("PRAGMA table_info(\""+safeChanName+"\");"); // executeQuery never null
ResultSet rs = statement.executeQuery("PRAGMA table_info(\""+channel+"\");"); // executeQuery never null
boolean[] schemaResultCheck = {false, false, false, false, false, false};
while (rs.next()) {
@ -116,8 +124,8 @@ public class BotSQLiteWorker implements Worker {
// Validating result: it table in DB have expected schema. If not, removing and recreating table.
for (boolean element: schemaResultCheck) {
if (!element) {
System.out.println("BotSQLiteWorker: Found already existing table for channel with incorrect syntax: removing table and re-creating.");
statement.executeUpdate("DROP TABLE \"" + safeChanName + "\";");
System.out.println("BotSQLiteWorker (@"+server+")->Constructor(): Notice:\n\tFound already existing table for channel with incorrect syntax: removing table and re-creating.");
statement.executeUpdate("DROP TABLE \"" + channel + "\";");
statement.executeUpdate(query);
break;
}
@ -125,17 +133,18 @@ public class BotSQLiteWorker implements Worker {
this.consistent = true;
this.preparedStatement = connection.prepareStatement(
"INSERT INTO \""+safeChanName
"INSERT INTO \""+channel
+"\" (unixtime, event, subject, message, object) "
+"VALUES (?, ?, ?, ?, ?);");
}
else {
System.out.println("BotSQLiteWorker (@"+server+")->constructor() failed:\n\t Connection to SQLite not established.");
this.consistent = false;
}
}
catch (SQLException e){
System.out.println("Internal issue: BotSQLiteWorker->constructor() failed\n\t"+e);
this.consistent = false;
System.out.println("BotSQLiteWorker (@"+server+")->constructor() failed:\n\t"+e);
this.consistent = false; // this.close();
}
}
@ -146,7 +155,7 @@ public class BotSQLiteWorker implements Worker {
public boolean isConsistent() {return consistent; }
@Override
public void logAdd(String event, String initiatorArg, String messageArg) {
public boolean logAdd(String event, String initiatorArg, String messageArg) {
try {
preparedStatement.setLong(1, getDate());
preparedStatement.setString(2, event);
@ -182,10 +191,14 @@ public class BotSQLiteWorker implements Worker {
}
preparedStatement.executeUpdate();
}
catch (SQLException e){
System.out.println("Internal issue: BotSQLiteWorker->logAdd() failed\n\t"+e);
this.consistent = false;
catch (SQLException sqle){
System.out.println("BotSQLiteWorker (@"+ircServer+")->logAdd() failed:\n\t"+sqle);
this.close(); // consistent will become false. Don't touch this.
}catch (NullPointerException npe){
System.out.println("BotSQLiteWorker (@"+ircServer+")->logAdd() failed:\n\t"+npe);
this.consistent = false; // most likely closed/non-opened file
}
return consistent;
}
@Override
@ -194,8 +207,9 @@ public class BotSQLiteWorker implements Worker {
//System.out.println("SQLite drier closed");
this.connection.close();
}
catch (SQLException e){
System.out.println("Internal issue: BotSQLiteWorker->close() failed\n\t" + e);
}
catch (SQLException | NullPointerException e){ //todo: consider redo
System.out.println("BotSQLiteWorker (@"+ircServer+")->close() failed:\n\t" + e); // nothing to do here
}
this.consistent = false;
}
}

View file

@ -5,7 +5,7 @@ public class BotZeroWorker implements Worker{
public boolean isConsistent() {return true;}
@Override
public void logAdd(String event, String initiatorArg, String messageArg) {}
public boolean logAdd(String event, String initiatorArg, String messageArg) { return true; }
@Override
public void close() {}

View file

@ -5,7 +5,7 @@ public interface Worker {
boolean isConsistent();
void logAdd(String event,
boolean logAdd(String event,
String initiatorArg,
String messageArg);

View file

@ -1,54 +0,0 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTest {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "MongoDB", new String[]{"192.168.1.5:27017",
"irc",
"loper",
"password"}))
System.out.println("Successful driver initiation");
else {
System.out.println("Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("LogFile1: "+fw1.isConsistent());
System.out.println("LogFile2: "+fw2.isConsistent());
System.out.println("LogFile3: "+fw3.isConsistent());
fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
fw1.close();
fw2.close();
fw3.close();
}
}
}

View file

@ -0,0 +1,71 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTestFiles {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "files", new String[]{"/tmp/logs/"}))
System.out.println("DRVT_Files: Successful driver initiation");
else {
System.out.println("DRVT_Files: Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("DRVT_Files:LogFile1: "+fw1.isConsistent());
System.out.println("DRVT_Files:LogFile2: "+fw2.isConsistent());
System.out.println("DRVT_Files:LogFile3: "+fw3.isConsistent());
boolean res;
res = fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
System.out.println("DRVT_Files:fw3 exec result: "+res);
fw1.close();
fw2.close();
fw3.close();
}
}
}

View file

@ -0,0 +1,73 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTestMongo {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "MongoDB", new String[]{"192.168.1.186:27017",
"irc",
"loper",
"password"}))
System.out.println("DRVT_Mongo:Successful driver initiation");
else {
System.out.println("DRVT_Mongo:Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("DRVT_Mongo:LogFile1: "+fw1.isConsistent());
System.out.println("DRVT_Mongo:LogFile2: "+fw2.isConsistent());
System.out.println("DRVT_Mongo:LogFile3: "+fw3.isConsistent());
boolean res;
res = fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
fw1.close();
fw2.close();
fw3.close();
}
}
}

View file

@ -0,0 +1,70 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTestSQLite {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "SQLite", new String[]{"/tmp/logs/mylogs"}))
System.out.println("DRVT_SQLite:Successful driver initiation");
else {
System.out.println("DRVT_SQLite:Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("DRVT_SQLite:LogFile1: "+fw1.isConsistent());
System.out.println("DRVT_SQLite:LogFile2: "+fw2.isConsistent());
System.out.println("DRVT_SQLite:LogFile3: "+fw3.isConsistent());
boolean res;
res = fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
fw1.close();
fw2.close();
fw3.close();
}
}
}