PageRenderTime 71ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/scala/log4jfugue/MongoTest.scala

http://github.com/btarbox/Log4ScalaFugue
Scala | 69 lines | 40 code | 7 blank | 22 comment | 5 complexity | 844c5ee99dbeab375b2eb022c5cdc35c MD5 | raw file
  1. package org.log4jfugue
  2. /*
  3. * Log4JFugue - Application Sonification
  4. * Copyright (C) 2011-2012 Brian Tarbox
  5. *
  6. * http://www.log4jfugue.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. import org.scalatest.matchers.ShouldMatchers
  24. import org.scala_tools.subcut.inject._
  25. import io.Source
  26. import org.scalatest.{FunSuite, SeveredStackTraces}
  27. import com.mongodb.casbah.Imports._
  28. import com.mongodb.casbah.commons.conversions.scala._
  29. class MongoTest extends FunSuite with ShouldMatchers {
  30. test("mongo test") {
  31. implicit val bindingModule = new NewBindingModule({ implicit module =>
  32. //implicit val bindingModule = module
  33. import module._
  34. bind[String] identifiedBy 'logFileName toSingle "c:/Users/gqx487/Downloads/server.log.4/server.log"
  35. bind[String] identifiedBy 'dateFormat toSingle "yyyy-MM-dd HH:mm:ss,SSS"
  36. bind[Array[Int]] identifiedBy 'currentSecond toSingle Array[Int](0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
  37. })
  38. val mongo = new MongoDataGetter()
  39. removeOldData(mongo)
  40. loadSomeData(mongo)
  41. find(mongo)
  42. }
  43. def removeOldData(mongo: MongoDataGetter) = {
  44. for ( x <- mongo.conn.find()) {
  45. mongo.conn.remove(x)
  46. }
  47. }
  48. def loadSomeData(mongo: MongoDataGetter) = {
  49. for(x <- 1 to 20) {
  50. val newObj = MongoDBObject("timestamp" -> x.toString,
  51. "category" -> "general",
  52. "msg" -> "bla bla bla")
  53. mongo.conn += newObj
  54. }
  55. }
  56. def find(mongo: MongoDataGetter) = {
  57. for { x <- mongo.conn.find().sort(MongoDBObject("timeColumn" -> "1")); thisTime = x.get("timestamp"); if(thisTime != null)} {
  58. println(x)
  59. println(thisTime)
  60. }
  61. }
  62. }