incubator-alois-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fla...@apache.org
Subject svn commit: r1031127 [6/22] - in /incubator/alois/trunk: ./ bin/ debian/ doc/ etc/ etc/alois/ etc/alois/apache2/ etc/alois/environments/ etc/alois/prisma/ etc/cron.d/ etc/default/ etc/logrotate.d/ prisma/ prisma/bin/ prisma/conf/ prisma/conf/prisma/ pr...
Date Thu, 04 Nov 2010 18:27:42 GMT
Added: incubator/alois/trunk/prisma/setup.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/setup.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/setup.rb (added)
+++ incubator/alois/trunk/prisma/setup.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,1600 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# setup.rb
+#
+# Copyright (c) 2000-2005 Minero Aoki
+#
+# This program is free software.
+# You can distribute/modify this program under the terms of
+# the GNU LGPL, Lesser General Public License version 2.1.
+#
+
+unless Enumerable.method_defined?(:map)   # Ruby 1.4.6
+  module Enumerable
+    alias map collect
+  end
+end
+
+unless File.respond_to?(:read)   # Ruby 1.6
+  def File.read(fname)
+    open(fname) {|f|
+      return f.read
+    }
+  end
+end
+
+unless Errno.const_defined?(:ENOTEMPTY)   # Windows?
+  module Errno
+    class ENOTEMPTY
+      # We do not raise this exception, implementation is not needed.
+    end
+  end
+end
+
+def File.binread(fname)
+  open(fname, 'rb') {|f|
+    return f.read
+  }
+end
+
+# for corrupted Windows' stat(2)
+def File.dir?(path)
+  File.directory?((path[-1,1] == '/') ? path : path + '/')
+end
+
+
+class ConfigTable
+
+  include Enumerable
+
+  def initialize(rbconfig)
+    @rbconfig = rbconfig
+    @items = []
+    @table = {}
+    # options
+    @install_prefix = nil
+    @config_opt = nil
+    @verbose = true
+    @no_harm = false
+  end
+
+  attr_accessor :install_prefix
+  attr_accessor :config_opt
+
+  attr_writer :verbose
+
+  def verbose?
+    @verbose
+  end
+
+  attr_writer :no_harm
+
+  def no_harm?
+    @no_harm
+  end
+
+  def [](key)
+    lookup(key).resolve(self)
+  end
+
+  def []=(key, val)
+    lookup(key).set val
+  end
+
+  def names
+    @items.map {|i| i.name }
+  end
+
+  def each(&block)
+    @items.each(&block)
+  end
+
+  def key?(name)
+    @table.key?(name)
+  end
+
+  def lookup(name)
+    @table[name] or setup_rb_error "no such config item: #{name}"
+  end
+
+  def add(item)
+    @items.push item
+    @table[item.name] = item
+  end
+
+  def remove(name)
+    item = lookup(name)
+    @items.delete_if {|i| i.name == name }
+    @table.delete_if {|name, i| i.name == name }
+    item
+  end
+
+  def load_script(path, inst = nil)
+    if File.file?(path)
+      MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path
+    end
+  end
+
+  def savefile
+    '.config'
+  end
+
+  def load_savefile
+    begin
+      File.foreach(savefile()) do |line|
+        k, v = *line.split(/=/, 2)
+        self[k] = v.strip
+      end
+    rescue Errno::ENOENT
+      setup_rb_error $!.message + "\n#{File.basename($0)} config first"
+    end
+  end
+
+  def save
+    @items.each {|i| i.value }
+    File.open(savefile(), 'w') {|f|
+      @items.each do |i|
+        f.printf "%s=%s\n", i.name, i.value if i.value? and i.value
+      end
+    }
+  end
+
+  def load_standard_entries
+    standard_entries(@rbconfig).each do |ent|
+      add ent
+    end
+  end
+
+  def standard_entries(rbconfig)
+    c = rbconfig
+
+    rubypath = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT'])
+
+    major = c['MAJOR'].to_i
+    minor = c['MINOR'].to_i
+    teeny = c['TEENY'].to_i
+    version = "#{major}.#{minor}"
+
+    # ruby ver. >= 1.4.4?
+    newpath_p = ((major >= 2) or
+                 ((major == 1) and
+                  ((minor >= 5) or
+                   ((minor == 4) and (teeny >= 4)))))
+
+    if c['rubylibdir']
+      # V > 1.6.3
+      libruby         = "#{c['prefix']}/lib/ruby"
+      librubyver      = c['rubylibdir']
+      librubyverarch  = c['archdir']
+      siteruby        = c['sitedir']
+      siterubyver     = c['sitelibdir']
+      siterubyverarch = c['sitearchdir']
+    elsif newpath_p
+      # 1.4.4 <= V <= 1.6.3
+      libruby         = "#{c['prefix']}/lib/ruby"
+      librubyver      = "#{c['prefix']}/lib/ruby/#{version}"
+      librubyverarch  = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
+      siteruby        = c['sitedir']
+      siterubyver     = "$siteruby/#{version}"
+      siterubyverarch = "$siterubyver/#{c['arch']}"
+    else
+      # V < 1.4.4
+      libruby         = "#{c['prefix']}/lib/ruby"
+      librubyver      = "#{c['prefix']}/lib/ruby/#{version}"
+      librubyverarch  = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
+      siteruby        = "#{c['prefix']}/lib/ruby/#{version}/site_ruby"
+      siterubyver     = siteruby
+      siterubyverarch = "$siterubyver/#{c['arch']}"
+    end
+    parameterize = lambda {|path|
+      path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')
+    }
+
+    if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
+      makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
+    else
+      makeprog = 'make'
+    end
+
+    [
+      ExecItem.new('installdirs', 'std/site/home',
+                   'std: install under libruby; site: install under site_ruby; home: install under $HOME')\
+          {|val, table|
+            case val
+            when 'std'
+              table['rbdir'] = '$librubyver'
+              table['sodir'] = '$librubyverarch'
+            when 'site'
+              table['rbdir'] = '$siterubyver'
+              table['sodir'] = '$siterubyverarch'
+            when 'home'
+              setup_rb_error '$HOME was not set' unless ENV['HOME']
+              table['prefix'] = ENV['HOME']
+              table['rbdir'] = '$libdir/ruby'
+              table['sodir'] = '$libdir/ruby'
+            end
+          },
+      PathItem.new('prefix', 'path', c['prefix'],
+                   'path prefix of target environment'),
+      PathItem.new('bindir', 'path', parameterize.call(c['bindir']),
+                   'the directory for commands'),
+      PathItem.new('libdir', 'path', parameterize.call(c['libdir']),
+                   'the directory for libraries'),
+      PathItem.new('datadir', 'path', parameterize.call(c['datadir']),
+                   'the directory for shared data'),
+      PathItem.new('mandir', 'path', parameterize.call(c['mandir']),
+                   'the directory for man pages'),
+      PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']),
+                   'the directory for system configuration files'),
+      PathItem.new('localstatedir', 'path', parameterize.call(c['localstatedir']),
+                   'the directory for local state data'),
+      PathItem.new('libruby', 'path', libruby,
+                   'the directory for ruby libraries'),
+      PathItem.new('librubyver', 'path', librubyver,
+                   'the directory for standard ruby libraries'),
+      PathItem.new('librubyverarch', 'path', librubyverarch,
+                   'the directory for standard ruby extensions'),
+      PathItem.new('siteruby', 'path', siteruby,
+          'the directory for version-independent aux ruby libraries'),
+      PathItem.new('siterubyver', 'path', siterubyver,
+                   'the directory for aux ruby libraries'),
+      PathItem.new('siterubyverarch', 'path', siterubyverarch,
+                   'the directory for aux ruby binaries'),
+      PathItem.new('rbdir', 'path', '$siterubyver',
+                   'the directory for ruby scripts'),
+      PathItem.new('sodir', 'path', '$siterubyverarch',
+                   'the directory for ruby extentions'),
+      PathItem.new('rubypath', 'path', rubypath,
+                   'the path to set to #! line'),
+      ProgramItem.new('rubyprog', 'name', rubypath,
+                      'the ruby program using for installation'),
+      ProgramItem.new('makeprog', 'name', makeprog,
+                      'the make program to compile ruby extentions'),
+      SelectItem.new('shebang', 'all/ruby/never', 'ruby',
+                     'shebang line (#!) editing mode'),
+      BoolItem.new('without-ext', 'yes/no', 'no',
+                   'does not compile/install ruby extentions')
+    ]
+  end
+  private :standard_entries
+
+  def load_multipackage_entries
+    multipackage_entries().each do |ent|
+      add ent
+    end
+  end
+
+  def multipackage_entries
+    [
+      PackageSelectionItem.new('with', 'name,name...', '', 'ALL',
+                               'package names that you want to install'),
+      PackageSelectionItem.new('without', 'name,name...', '', 'NONE',
+                               'package names that you do not want to install')
+    ]
+  end
+  private :multipackage_entries
+
+  ALIASES = {
+    'std-ruby'         => 'librubyver',
+    'stdruby'          => 'librubyver',
+    'rubylibdir'       => 'librubyver',
+    'archdir'          => 'librubyverarch',
+    'site-ruby-common' => 'siteruby',     # For backward compatibility
+    'site-ruby'        => 'siterubyver',  # For backward compatibility
+    'bin-dir'          => 'bindir',
+    'bin-dir'          => 'bindir',
+    'rb-dir'           => 'rbdir',
+    'so-dir'           => 'sodir',
+    'data-dir'         => 'datadir',
+    'ruby-path'        => 'rubypath',
+    'ruby-prog'        => 'rubyprog',
+    'ruby'             => 'rubyprog',
+    'make-prog'        => 'makeprog',
+    'make'             => 'makeprog'
+  }
+
+  def fixup
+    ALIASES.each do |ali, name|
+      @table[ali] = @table[name]
+    end
+  end
+
+  def options_re
+    /\A--(#{@table.keys.join('|')})(?:=(.*))?\z/
+  end
+
+  def parse_opt(opt)
+    m = options_re().match(opt) or setup_rb_error "config: unknown option #{opt}"
+    m.to_a[1,2]
+  end
+
+  def dllext
+    @rbconfig['DLEXT']
+  end
+
+  def value_config?(name)
+    lookup(name).value?
+  end
+
+  class Item
+    def initialize(name, template, default, desc)
+      @name = name.freeze
+      @template = template
+      @value = default
+      @default = default
+      @description = desc
+    end
+
+    attr_reader :name
+    attr_reader :description
+
+    attr_accessor :default
+    alias help_default default
+
+    def help_opt
+      "--#{@name}=#{@template}"
+    end
+
+    def value?
+      true
+    end
+
+    def value
+      @value
+    end
+
+    def resolve(table)
+      @value.gsub(%r<\$([^/]+)>) { table[$1] }
+    end
+
+    def set(val)
+      @value = check(val)
+    end
+
+    private
+
+    def check(val)
+      setup_rb_error "config: --#{name} requires argument" unless val
+      val
+    end
+  end
+
+  class BoolItem < Item
+    def config_type
+      'bool'
+    end
+
+    def help_opt
+      "--#{@name}"
+    end
+
+    private
+
+    def check(val)
+      return 'yes' unless val
+      case val
+      when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes'
+      when /\An(o)?\z/i, /\Af(alse)\z/i  then 'no'
+      else
+        setup_rb_error "config: --#{@name} accepts only yes/no for argument"
+      end
+    end
+  end
+
+  class PathItem < Item
+    def config_type
+      'path'
+    end
+
+    private
+
+    def check(path)
+      setup_rb_error "config: --#{@name} requires argument"  unless path
+      path[0,1] == '$' ? path : File.expand_path(path)
+    end
+  end
+
+  class ProgramItem < Item
+    def config_type
+      'program'
+    end
+  end
+
+  class SelectItem < Item
+    def initialize(name, selection, default, desc)
+      super
+      @ok = selection.split('/')
+    end
+
+    def config_type
+      'select'
+    end
+
+    private
+
+    def check(val)
+      unless @ok.include?(val.strip)
+        setup_rb_error "config: use --#{@name}=#{@template} (#{val})"
+      end
+      val.strip
+    end
+  end
+
+  class ExecItem < Item
+    def initialize(name, selection, desc, &block)
+      super name, selection, nil, desc
+      @ok = selection.split('/')
+      @action = block
+    end
+
+    def config_type
+      'exec'
+    end
+
+    def value?
+      false
+    end
+
+    def resolve(table)
+      setup_rb_error "$#{name()} wrongly used as option value"
+    end
+
+    undef set
+
+    def evaluate(val, table)
+      v = val.strip.downcase
+      unless @ok.include?(v)
+        setup_rb_error "invalid option --#{@name}=#{val} (use #{@template})"
+      end
+      @action.call v, table
+    end
+  end
+
+  class PackageSelectionItem < Item
+    def initialize(name, template, default, help_default, desc)
+      super name, template, default, desc
+      @help_default = help_default
+    end
+
+    attr_reader :help_default
+
+    def config_type
+      'package'
+    end
+
+    private
+
+    def check(val)
+      unless File.dir?("packages/#{val}")
+        setup_rb_error "config: no such package: #{val}"
+      end
+      val
+    end
+  end
+
+  class MetaConfigEnvironment
+    def initialize(config, installer)
+      @config = config
+      @installer = installer
+    end
+
+    def config_names
+      @config.names
+    end
+
+    def config?(name)
+      @config.key?(name)
+    end
+
+    def bool_config?(name)
+      @config.lookup(name).config_type == 'bool'
+    end
+
+    def path_config?(name)
+      @config.lookup(name).config_type == 'path'
+    end
+
+    def value_config?(name)
+      @config.lookup(name).config_type != 'exec'
+    end
+
+    def add_config(item)
+      @config.add item
+    end
+
+    def add_bool_config(name, default, desc)
+      @config.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
+    end
+
+    def add_path_config(name, default, desc)
+      @config.add PathItem.new(name, 'path', default, desc)
+    end
+
+    def set_config_default(name, default)
+      @config.lookup(name).default = default
+    end
+
+    def remove_config(name)
+      @config.remove(name)
+    end
+
+    # For only multipackage
+    def packages
+      raise '[setup.rb fatal] multi-package metaconfig API packages() called for single-package; contact application package vendor' unless @installer
+      @installer.packages
+    end
+
+    # For only multipackage
+    def declare_packages(list)
+      raise '[setup.rb fatal] multi-package metaconfig API declare_packages() called for single-package; contact application package vendor' unless @installer
+      @installer.packages = list
+    end
+  end
+
+end   # class ConfigTable
+
+
+# This module requires: #verbose?, #no_harm?
+module FileOperations
+
+  def mkdir_p(dirname, prefix = nil)
+    dirname = prefix + File.expand_path(dirname) if prefix
+    $stderr.puts "mkdir -p #{dirname}" if verbose?
+    return if no_harm?
+
+    # Does not check '/', it's too abnormal.
+    dirs = File.expand_path(dirname).split(%r<(?=/)>)
+    if /\A[a-z]:\z/i =~ dirs[0]
+      disk = dirs.shift
+      dirs[0] = disk + dirs[0]
+    end
+    dirs.each_index do |idx|
+      path = dirs[0..idx].join('')
+      Dir.mkdir path unless File.dir?(path)
+    end
+  end
+
+  def rm_f(path)
+    $stderr.puts "rm -f #{path}" if verbose?
+    return if no_harm?
+    force_remove_file path
+  end
+
+  def rm_rf(path)
+    $stderr.puts "rm -rf #{path}" if verbose?
+    return if no_harm?
+    remove_tree path
+  end
+
+  def remove_tree(path)
+    if File.symlink?(path)
+      remove_file path
+    elsif File.dir?(path)
+      remove_tree0 path
+    else
+      force_remove_file path
+    end
+  end
+
+  def remove_tree0(path)
+    Dir.foreach(path) do |ent|
+      next if ent == '.'
+      next if ent == '..'
+      entpath = "#{path}/#{ent}"
+      if File.symlink?(entpath)
+        remove_file entpath
+      elsif File.dir?(entpath)
+        remove_tree0 entpath
+      else
+        force_remove_file entpath
+      end
+    end
+    begin
+      Dir.rmdir path
+    rescue Errno::ENOTEMPTY
+      # directory may not be empty
+    end
+  end
+
+  def move_file(src, dest)
+    force_remove_file dest
+    begin
+      File.rename src, dest
+    rescue
+      File.open(dest, 'wb') {|f|
+        f.write File.binread(src)
+      }
+      File.chmod File.stat(src).mode, dest
+      File.unlink src
+    end
+  end
+
+  def force_remove_file(path)
+    begin
+      remove_file path
+    rescue
+    end
+  end
+
+  def remove_file(path)
+    File.chmod 0777, path
+    File.unlink path
+  end
+
+  def install(from, dest, mode, prefix = nil)
+    $stderr.puts "install #{from} #{dest}" if verbose?
+    return if no_harm?
+
+    realdest = prefix ? prefix + File.expand_path(dest) : dest
+    realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
+    str = File.binread(from)
+    if diff?(str, realdest)
+      verbose_off {
+        rm_f realdest if File.exist?(realdest)
+      }
+      File.open(realdest, 'wb') {|f|
+        f.write str
+      }
+      File.chmod mode, realdest
+
+      File.open("#{objdir_root()}/InstalledFiles", 'a') {|f|
+        if prefix
+          f.puts realdest.sub(prefix, '')
+        else
+          f.puts realdest
+        end
+      }
+    end
+  end
+
+  def diff?(new_content, path)
+    return true unless File.exist?(path)
+    new_content != File.binread(path)
+  end
+
+  def command(*args)
+    $stderr.puts args.join(' ') if verbose?
+    system(*args) or raise RuntimeError,
+        "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
+  end
+
+  def ruby(*args)
+    command config('rubyprog'), *args
+  end
+  
+  def make(task = nil)
+    command(*[config('makeprog'), task].compact)
+  end
+
+  def extdir?(dir)
+    File.exist?("#{dir}/MANIFEST") or File.exist?("#{dir}/extconf.rb")
+  end
+
+  def files_of(dir)
+    Dir.open(dir) {|d|
+      return d.select {|ent| File.file?("#{dir}/#{ent}") }
+    }
+  end
+
+  DIR_REJECT = %w( . .. CVS SCCS RCS CVS.adm .svn )
+
+  def directories_of(dir)
+    Dir.open(dir) {|d|
+      return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT
+    }
+  end
+
+end
+
+
+# This module requires: #srcdir_root, #objdir_root, #relpath
+module HookScriptAPI
+
+  def get_config(key)
+    @config[key]
+  end
+
+  alias config get_config
+
+  # obsolete: use metaconfig to change configuration
+  def set_config(key, val)
+    @config[key] = val
+  end
+
+  #
+  # srcdir/objdir (works only in the package directory)
+  #
+
+  def curr_srcdir
+    "#{srcdir_root()}/#{relpath()}"
+  end
+
+  def curr_objdir
+    "#{objdir_root()}/#{relpath()}"
+  end
+
+  def srcfile(path)
+    "#{curr_srcdir()}/#{path}"
+  end
+
+  def srcexist?(path)
+    File.exist?(srcfile(path))
+  end
+
+  def srcdirectory?(path)
+    File.dir?(srcfile(path))
+  end
+  
+  def srcfile?(path)
+    File.file?(srcfile(path))
+  end
+
+  def srcentries(path = '.')
+    Dir.open("#{curr_srcdir()}/#{path}") {|d|
+      return d.to_a - %w(. ..)
+    }
+  end
+
+  def srcfiles(path = '.')
+    srcentries(path).select {|fname|
+      File.file?(File.join(curr_srcdir(), path, fname))
+    }
+  end
+
+  def srcdirectories(path = '.')
+    srcentries(path).select {|fname|
+      File.dir?(File.join(curr_srcdir(), path, fname))
+    }
+  end
+
+end
+
+
+class ToplevelInstaller
+
+  Version   = '3.4.1'
+  Copyright = 'Copyright (c) 2000-2005 Minero Aoki'
+
+  TASKS = [
+    [ 'all',      'do config, setup, then install' ],
+    [ 'config',   'saves your configurations' ],
+    [ 'show',     'shows current configuration' ],
+    [ 'setup',    'compiles ruby extentions and others' ],
+    [ 'install',  'installs files' ],
+    [ 'test',     'run all tests in test/' ],
+    [ 'clean',    "does `make clean' for each extention" ],
+    [ 'distclean',"does `make distclean' for each extention" ]
+  ]
+
+  def ToplevelInstaller.invoke
+    config = ConfigTable.new(load_rbconfig())
+    config.load_standard_entries
+    config.load_multipackage_entries if multipackage?
+    config.fixup
+    klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller)
+    klass.new(File.dirname($0), config).invoke
+  end
+
+  def ToplevelInstaller.multipackage?
+    File.dir?(File.dirname($0) + '/packages')
+  end
+
+  def ToplevelInstaller.load_rbconfig
+    if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
+      ARGV.delete(arg)
+      load File.expand_path(arg.split(/=/, 2)[1])
+      $".push 'rbconfig.rb'
+    else
+      require 'rbconfig'
+    end
+    ::Config::CONFIG
+  end
+
+  def initialize(ardir_root, config)
+    @ardir = File.expand_path(ardir_root)
+    @config = config
+    # cache
+    @valid_task_re = nil
+  end
+
+  def config(key)
+    @config[key]
+  end
+
+  def inspect
+    "#<#{self.class} #{__id__()}>"
+  end
+
+  def invoke
+    run_metaconfigs
+    case task = parsearg_global()
+    when nil, 'all'
+      parsearg_config
+      init_installers
+      exec_config
+      exec_setup
+      exec_install
+    else
+      case task
+      when 'config', 'test'
+        ;
+      when 'clean', 'distclean'
+        @config.load_savefile if File.exist?(@config.savefile)
+      else
+        @config.load_savefile
+      end
+      __send__ "parsearg_#{task}"
+      init_installers
+      __send__ "exec_#{task}"
+    end
+  end
+  
+  def run_metaconfigs
+    @config.load_script "#{@ardir}/metaconfig"
+  end
+
+  def init_installers
+    @installer = Installer.new(@config, @ardir, File.expand_path('.'))
+  end
+
+  #
+  # Hook Script API bases
+  #
+
+  def srcdir_root
+    @ardir
+  end
+
+  def objdir_root
+    '.'
+  end
+
+  def relpath
+    '.'
+  end
+
+  #
+  # Option Parsing
+  #
+
+  def parsearg_global
+    while arg = ARGV.shift
+      case arg
+      when /\A\w+\z/
+        setup_rb_error "invalid task: #{arg}" unless valid_task?(arg)
+        return arg
+      when '-q', '--quiet'
+        @config.verbose = false
+      when '--verbose'
+        @config.verbose = true
+      when '--help'
+        print_usage $stdout
+        exit 0
+      when '--version'
+        puts "#{File.basename($0)} version #{Version}"
+        exit 0
+      when '--copyright'
+        puts Copyright
+        exit 0
+      else
+        setup_rb_error "unknown global option '#{arg}'"
+      end
+    end
+    nil
+  end
+
+  def valid_task?(t)
+    valid_task_re() =~ t
+  end
+
+  def valid_task_re
+    @valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/
+  end
+
+  def parsearg_no_options
+    unless ARGV.empty?
+      task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1)
+      setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"
+    end
+  end
+
+  alias parsearg_show       parsearg_no_options
+  alias parsearg_setup      parsearg_no_options
+  alias parsearg_test       parsearg_no_options
+  alias parsearg_clean      parsearg_no_options
+  alias parsearg_distclean  parsearg_no_options
+
+  def parsearg_config
+    evalopt = []
+    set = []
+    @config.config_opt = []
+    while i = ARGV.shift
+      if /\A--?\z/ =~ i
+        @config.config_opt = ARGV.dup
+        break
+      end
+      name, value = *@config.parse_opt(i)
+      if @config.value_config?(name)
+        @config[name] = value
+      else
+        evalopt.push [name, value]
+      end
+      set.push name
+    end
+    evalopt.each do |name, value|
+      @config.lookup(name).evaluate value, @config
+    end
+    # Check if configuration is valid
+    set.each do |n|
+      @config[n] if @config.value_config?(n)
+    end
+  end
+
+  def parsearg_install
+    @config.no_harm = false
+    @config.install_prefix = ''
+    while a = ARGV.shift
+      case a
+      when '--no-harm'
+        @config.no_harm = true
+      when /\A--prefix=/
+        path = a.split(/=/, 2)[1]
+        path = File.expand_path(path) unless path[0,1] == '/'
+        @config.install_prefix = path
+      else
+        setup_rb_error "install: unknown option #{a}"
+      end
+    end
+  end
+
+  def print_usage(out)
+    out.puts 'Typical Installation Procedure:'
+    out.puts "  $ ruby #{File.basename $0} config"
+    out.puts "  $ ruby #{File.basename $0} setup"
+    out.puts "  # ruby #{File.basename $0} install (may require root privilege)"
+    out.puts
+    out.puts 'Detailed Usage:'
+    out.puts "  ruby #{File.basename $0} <global option>"
+    out.puts "  ruby #{File.basename $0} [<global options>] <task> [<task options>]"
+
+    fmt = "  %-24s %s\n"
+    out.puts
+    out.puts 'Global options:'
+    out.printf fmt, '-q,--quiet',   'suppress message outputs'
+    out.printf fmt, '   --verbose', 'output messages verbosely'
+    out.printf fmt, '   --help',    'print this message'
+    out.printf fmt, '   --version', 'print version and quit'
+    out.printf fmt, '   --copyright',  'print copyright and quit'
+    out.puts
+    out.puts 'Tasks:'
+    TASKS.each do |name, desc|
+      out.printf fmt, name, desc
+    end
+
+    fmt = "  %-24s %s [%s]\n"
+    out.puts
+    out.puts 'Options for CONFIG or ALL:'
+    @config.each do |item|
+      out.printf fmt, item.help_opt, item.description, item.help_default
+    end
+    out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
+    out.puts
+    out.puts 'Options for INSTALL:'
+    out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
+    out.printf fmt, '--prefix=path',  'install path prefix', ''
+    out.puts
+  end
+
+  #
+  # Task Handlers
+  #
+
+  def exec_config
+    @installer.exec_config
+    @config.save   # must be final
+  end
+
+  def exec_setup
+    @installer.exec_setup
+  end
+
+  def exec_install
+    @installer.exec_install
+  end
+
+  def exec_test
+    @installer.exec_test
+  end
+
+  def exec_show
+    @config.each do |i|
+      printf "%-20s %s\n", i.name, i.value if i.value?
+    end
+  end
+
+  def exec_clean
+    @installer.exec_clean
+  end
+
+  def exec_distclean
+    @installer.exec_distclean
+  end
+
+end   # class ToplevelInstaller
+
+
+class ToplevelInstallerMulti < ToplevelInstaller
+
+  include FileOperations
+
+  def initialize(ardir_root, config)
+    super
+    @packages = directories_of("#{@ardir}/packages")
+    raise 'no package exists' if @packages.empty?
+    @root_installer = Installer.new(@config, @ardir, File.expand_path('.'))
+  end
+
+  def run_metaconfigs
+    @config.load_script "#{@ardir}/metaconfig", self
+    @packages.each do |name|
+      @config.load_script "#{@ardir}/packages/#{name}/metaconfig"
+    end
+  end
+
+  attr_reader :packages
+
+  def packages=(list)
+    raise 'package list is empty' if list.empty?
+    list.each do |name|
+      raise "directory packages/#{name} does not exist"\
+              unless File.dir?("#{@ardir}/packages/#{name}")
+    end
+    @packages = list
+  end
+
+  def init_installers
+    @installers = {}
+    @packages.each do |pack|
+      @installers[pack] = Installer.new(@config,
+                                       "#{@ardir}/packages/#{pack}",
+                                       "packages/#{pack}")
+    end
+    with    = extract_selection(config('with'))
+    without = extract_selection(config('without'))
+    @selected = @installers.keys.select {|name|
+                  (with.empty? or with.include?(name)) \
+                      and not without.include?(name)
+                }
+  end
+
+  def extract_selection(list)
+    a = list.split(/,/)
+    a.each do |name|
+      setup_rb_error "no such package: #{name}"  unless @installers.key?(name)
+    end
+    a
+  end
+
+  def print_usage(f)
+    super
+    f.puts 'Inluded packages:'
+    f.puts '  ' + @packages.sort.join(' ')
+    f.puts
+  end
+
+  #
+  # Task Handlers
+  #
+
+  def exec_config
+    run_hook 'pre-config'
+    each_selected_installers {|inst| inst.exec_config }
+    run_hook 'post-config'
+    @config.save   # must be final
+  end
+
+  def exec_setup
+    run_hook 'pre-setup'
+    each_selected_installers {|inst| inst.exec_setup }
+    run_hook 'post-setup'
+  end
+
+  def exec_install
+    run_hook 'pre-install'
+    each_selected_installers {|inst| inst.exec_install }
+    run_hook 'post-install'
+  end
+
+  def exec_test
+    run_hook 'pre-test'
+    each_selected_installers {|inst| inst.exec_test }
+    run_hook 'post-test'
+  end
+
+  def exec_clean
+    rm_f @config.savefile
+    run_hook 'pre-clean'
+    each_selected_installers {|inst| inst.exec_clean }
+    run_hook 'post-clean'
+  end
+
+  def exec_distclean
+    rm_f @config.savefile
+    run_hook 'pre-distclean'
+    each_selected_installers {|inst| inst.exec_distclean }
+    run_hook 'post-distclean'
+  end
+
+  #
+  # lib
+  #
+
+  def each_selected_installers
+    Dir.mkdir 'packages' unless File.dir?('packages')
+    @selected.each do |pack|
+      $stderr.puts "Processing the package `#{pack}' ..." if verbose?
+      Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}")
+      Dir.chdir "packages/#{pack}"
+      yield @installers[pack]
+      Dir.chdir '../..'
+    end
+  end
+
+  def run_hook(id)
+    @root_installer.run_hook id
+  end
+
+  # module FileOperations requires this
+  def verbose?
+    @config.verbose?
+  end
+
+  # module FileOperations requires this
+  def no_harm?
+    @config.no_harm?
+  end
+
+end   # class ToplevelInstallerMulti
+
+
+class Installer
+
+  FILETYPES = %w( bin lib ext data conf man )
+
+  include FileOperations
+  include HookScriptAPI
+
+  def initialize(config, srcroot, objroot)
+    @config = config
+    @srcdir = File.expand_path(srcroot)
+    @objdir = File.expand_path(objroot)
+    @currdir = '.'
+  end
+
+  def inspect
+    "#<#{self.class} #{File.basename(@srcdir)}>"
+  end
+
+  def noop(rel)
+  end
+
+  #
+  # Hook Script API base methods
+  #
+
+  def srcdir_root
+    @srcdir
+  end
+
+  def objdir_root
+    @objdir
+  end
+
+  def relpath
+    @currdir
+  end
+
+  #
+  # Config Access
+  #
+
+  # module FileOperations requires this
+  def verbose?
+    @config.verbose?
+  end
+
+  # module FileOperations requires this
+  def no_harm?
+    @config.no_harm?
+  end
+
+  def verbose_off
+    begin
+      save, @config.verbose = @config.verbose?, false
+      yield
+    ensure
+      @config.verbose = save
+    end
+  end
+
+  #
+  # TASK config
+  #
+
+  def exec_config
+    exec_task_traverse 'config'
+  end
+
+  alias config_dir_bin noop
+  alias config_dir_lib noop
+
+  def config_dir_ext(rel)
+    extconf if extdir?(curr_srcdir())
+  end
+
+  alias config_dir_data noop
+  alias config_dir_conf noop
+  alias config_dir_man noop
+
+  def extconf
+    ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
+  end
+
+  #
+  # TASK setup
+  #
+
+  def exec_setup
+    exec_task_traverse 'setup'
+  end
+
+  def setup_dir_bin(rel)
+    files_of(curr_srcdir()).each do |fname|
+      update_shebang_line "#{curr_srcdir()}/#{fname}"
+    end
+  end
+
+  alias setup_dir_lib noop
+
+  def setup_dir_ext(rel)
+    make if extdir?(curr_srcdir())
+  end
+
+  alias setup_dir_data noop
+  alias setup_dir_conf noop
+  alias setup_dir_man noop
+
+  def update_shebang_line(path)
+    return if no_harm?
+    return if config('shebang') == 'never'
+    old = Shebang.load(path)
+    if old
+      $stderr.puts "warning: #{path}: Shebang line includes too many args.  It is not portable and your program may not work." if old.args.size > 1
+      new = new_shebang(old)
+      return if new.to_s == old.to_s
+    else
+      return unless config('shebang') == 'all'
+      new = Shebang.new(config('rubypath'))
+    end
+    $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
+    open_atomic_writer(path) {|output|
+      File.open(path, 'rb') {|f|
+        f.gets if old   # discard
+        output.puts new.to_s
+        output.print f.read
+      }
+    }
+  end
+
+  def new_shebang(old)
+    if /\Aruby/ =~ File.basename(old.cmd)
+      Shebang.new(config('rubypath'), old.args)
+    elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
+      Shebang.new(config('rubypath'), old.args[1..-1])
+    else
+      return old unless config('shebang') == 'all'
+      Shebang.new(config('rubypath'))
+    end
+  end
+
+  def open_atomic_writer(path, &block)
+    tmpfile = File.basename(path) + '.tmp'
+    begin
+      File.open(tmpfile, 'wb', &block)
+      File.rename tmpfile, File.basename(path)
+    ensure
+      File.unlink tmpfile if File.exist?(tmpfile)
+    end
+  end
+
+  class Shebang
+    def Shebang.load(path)
+      line = nil
+      File.open(path) {|f|
+        line = f.gets
+      }
+      return nil unless /\A#!/ =~ line
+      parse(line)
+    end
+
+    def Shebang.parse(line)
+      cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
+      new(cmd, args)
+    end
+
+    def initialize(cmd, args = [])
+      @cmd = cmd
+      @args = args
+    end
+
+    attr_reader :cmd
+    attr_reader :args
+
+    def to_s
+      "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
+    end
+  end
+
+  #
+  # TASK install
+  #
+
+  def exec_install
+    rm_f 'InstalledFiles'
+    exec_task_traverse 'install'
+  end
+
+  def install_dir_bin(rel)
+    install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
+  end
+
+  def install_dir_lib(rel)
+    install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
+  end
+
+  def install_dir_ext(rel)
+    return unless extdir?(curr_srcdir())
+    install_files rubyextentions('.'),
+                  "#{config('sodir')}/#{File.dirname(rel)}",
+                  0555
+  end
+
+  def install_dir_data(rel)
+    install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644
+  end
+
+  def install_dir_conf(rel)
+    # FIXME: should not remove current config files
+    # (rename previous file to .old/.org)
+    install_files targetfiles(), "#{config('sysconfdir')}/#{rel}", 0644
+  end
+
+  def install_dir_man(rel)
+    install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
+  end
+
+  def install_files(list, dest, mode)
+    mkdir_p dest, @config.install_prefix
+    list.each do |fname|
+      install fname, dest, mode, @config.install_prefix
+    end
+  end
+
+  def libfiles
+    glob_reject(%w(*.y *.output), targetfiles())
+  end
+
+  def rubyextentions(dir)
+    ents = glob_select("*.#{@config.dllext}", targetfiles())
+    if ents.empty?
+      setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
+    end
+    ents
+  end
+
+  def targetfiles
+    mapdir(existfiles() - hookfiles())
+  end
+
+  def mapdir(ents)
+    ents.map {|ent|
+      if File.exist?(ent)
+      then ent                         # objdir
+      else "#{curr_srcdir()}/#{ent}"   # srcdir
+      end
+    }
+  end
+
+  # picked up many entries from cvs-1.11.1/src/ignore.c
+  JUNK_FILES = %w( 
+    core RCSLOG tags TAGS .make.state
+    .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
+    *~ *.old *.bak *.BAK *.orig *.rej _$* *$
+
+    *.org *.in .*
+  )
+
+  def existfiles
+    glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
+  end
+
+  def hookfiles
+    %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt|
+      %w( config setup install clean ).map {|t| sprintf(fmt, t) }
+    }.flatten
+  end
+
+  def glob_select(pat, ents)
+    re = globs2re([pat])
+    ents.select {|ent| re =~ ent }
+  end
+
+  def glob_reject(pats, ents)
+    re = globs2re(pats)
+    ents.reject {|ent| re =~ ent }
+  end
+
+  GLOB2REGEX = {
+    '.' => '\.',
+    '$' => '\$',
+    '#' => '\#',
+    '*' => '.*'
+  }
+
+  def globs2re(pats)
+    /\A(?:#{
+      pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|')
+    })\z/
+  end
+
+  #
+  # TASK test
+  #
+
+  TESTDIR = 'test'
+
+  def exec_test
+    unless File.directory?('test')
+      $stderr.puts 'no test in this package' if verbose?
+      return
+    end
+    $stderr.puts 'Running tests...' if verbose?
+    begin
+      require 'test/unit'
+    rescue LoadError
+      setup_rb_error 'test/unit cannot loaded.  You need Ruby 1.8 or later to invoke this task.'
+    end
+    runner = Test::Unit::AutoRunner.new(true)
+    runner.to_run << TESTDIR
+    runner.run
+  end
+
+  #
+  # TASK clean
+  #
+
+  def exec_clean
+    exec_task_traverse 'clean'
+    rm_f @config.savefile
+    rm_f 'InstalledFiles'
+  end
+
+  alias clean_dir_bin noop
+  alias clean_dir_lib noop
+  alias clean_dir_data noop
+  alias clean_dir_conf noop
+  alias clean_dir_man noop
+
+  def clean_dir_ext(rel)
+    return unless extdir?(curr_srcdir())
+    make 'clean' if File.file?('Makefile')
+  end
+
+  #
+  # TASK distclean
+  #
+
+  def exec_distclean
+    exec_task_traverse 'distclean'
+    rm_f @config.savefile
+    rm_f 'InstalledFiles'
+  end
+
+  alias distclean_dir_bin noop
+  alias distclean_dir_lib noop
+
+  def distclean_dir_ext(rel)
+    return unless extdir?(curr_srcdir())
+    make 'distclean' if File.file?('Makefile')
+  end
+
+  alias distclean_dir_data noop
+  alias distclean_dir_conf noop
+  alias distclean_dir_man noop
+
+  #
+  # Traversing
+  #
+
+  def exec_task_traverse(task)
+    run_hook "pre-#{task}"
+    FILETYPES.each do |type|
+      if type == 'ext' and config('without-ext') == 'yes'
+        $stderr.puts 'skipping ext/* by user option' if verbose?
+        next
+      end
+      traverse task, type, "#{task}_dir_#{type}"
+    end
+    run_hook "post-#{task}"
+  end
+
+  def traverse(task, rel, mid)
+    dive_into(rel) {
+      run_hook "pre-#{task}"
+      __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
+      directories_of(curr_srcdir()).each do |d|
+        traverse task, "#{rel}/#{d}", mid
+      end
+      run_hook "post-#{task}"
+    }
+  end
+
+  def dive_into(rel)
+    return unless File.dir?("#{@srcdir}/#{rel}")
+
+    dir = File.basename(rel)
+    Dir.mkdir dir unless File.dir?(dir)
+    prevdir = Dir.pwd
+    Dir.chdir dir
+    $stderr.puts '---> ' + rel if verbose?
+    @currdir = rel
+    yield
+    Dir.chdir prevdir
+    $stderr.puts '<--- ' + rel if verbose?
+    @currdir = File.dirname(rel)
+  end
+
+  def run_hook(id)
+    path = [ "#{curr_srcdir()}/#{id}",
+             "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) }
+    return unless path
+    begin
+      instance_eval File.read(path), path, 1
+    rescue
+      raise if $DEBUG
+      setup_rb_error "hook #{path} failed:\n" + $!.message
+    end
+  end
+
+end   # class Installer
+
+
+class SetupError < StandardError; end
+
+def setup_rb_error(msg)
+  raise SetupError, msg
+end
+
+if $0 == __FILE__
+  begin
+    ToplevelInstaller.invoke
+  rescue SetupError
+    raise if $DEBUG
+    $stderr.puts $!.message
+    $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
+    exit 1
+  end
+end

Added: incubator/alois/trunk/prisma/test/fixtures/compression_metas.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/compression_metas.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/compression_metas.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/compression_metas.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,15 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+  extname: MyString
+  inflate_command: MyString
+  inflated_size: 1
+  deflated_size: 1
+  file_metas_id: 1
+
+two:
+  extname: MyString
+  inflate_command: MyString
+  inflated_size: 1
+  deflated_size: 1
+  file_metas_id: 1

Added: incubator/alois/trunk/prisma/test/fixtures/file_metas.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/file_metas.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/file_metas.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/file_metas.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,7 @@
+one:
+ id: 1
+ options: "filetype=log"
+
+two:
+ id: 2
+ options: "a=xyz, filetype=syslog ,b=zyx"

Added: incubator/alois/trunk/prisma/test/fixtures/file_raws.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/file_raws.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/file_raws.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/file_raws.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,14 @@
+file1:
+ id: 1
+ dirname: "/var/log/messages"
+ basename: "messages"
+ ftype: "bz2"
+ size: "403"
+ mtime: 2008-01-01 10:00:00
+ atime: 2008-01-01 10:00:00
+ ctime: 2008-01-01 10:00:00
+ umask: 700
+ uid: 1000
+ gid: 1000
+ options: "filetype=syslog"
+ msg: "Apr 28 06:38:28 host1.example.com Some Message\nApr 28 06:38:29 host1.example.com Some Message 2\nApr 28 06:38:34 host3 syslogd 1.4.1#18: restart.\nApr 28 06:39:51 host1.example.com last message repeated 3 times\nApr 28 06:38:42 host3.example.com kernel: Redirect from 192.168.1.1 on tap11 about 192.168.11.111 ignored.\nApr 28 06:55:28 host1.example.com CRON[30589]: (pam_unix) session closed for user root\n"

Added: incubator/alois/trunk/prisma/test/fixtures/inet_header_metas.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/inet_header_metas.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/inet_header_metas.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/inet_header_metas.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+  id: 1
+two:
+  id: 2

Added: incubator/alois/trunk/prisma/test/fixtures/inet_object_metas.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/inet_object_metas.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/inet_object_metas.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/inet_object_metas.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+  id: 1
+two:
+  id: 2

Added: incubator/alois/trunk/prisma/test/fixtures/log_metas.csv
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/log_metas.csv?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/log_metas.csv (added)
+++ incubator/alois/trunk/prisma/test/fixtures/log_metas.csv Thu Nov  4 18:27:22 2010
@@ -0,0 +1,81 @@
+id,date,time,host,hash_value,syslogd_metas_id,pure_metas_id,file_metas_id
+1,"2007-04-30","10:30:20","warning.example.com",\N,83,\N,\N
+2,"2007-05-01","10:30:20","debug.example.com",\N,84,\N,\N
+3,"2007-05-01","10:30:20","err.example.com",\N,85,\N,\N
+4,"2007-04-30","10:30:20","alert.example.com",\N,86,\N,\N
+5,"2007-05-01","10:30:20","emerg.example.com",\N,87,\N,\N
+6,"2007-04-30","10:30:20","emerg.example.com",\N,88,\N,\N
+7,"2007-04-30","10:30:20","debug.example.com",\N,89,\N,\N
+8,"2007-05-01","10:30:20","warning.example.com",\N,90,\N,\N
+9,"2007-04-30","10:30:20","crit.example.com",\N,91,\N,\N
+10,"2007-05-01","10:30:20","warning.example.com",\N,92,\N,\N
+11,"2007-05-01","10:30:20","notice.example.com",\N,93,\N,\N
+12,"2007-04-30","10:30:20","err.example.com",\N,94,\N,\N
+13,"2007-05-01","10:30:20","err.example.com",\N,95,\N,\N
+14,"2007-04-30","10:30:20","err.example.com",\N,96,\N,\N
+15,"2007-05-01","10:30:20","debug.example.com",\N,97,\N,\N
+16,"2007-04-30","10:30:20","notice.example.com",\N,98,\N,\N
+17,"2007-04-30","10:30:20","err.example.com",\N,99,\N,\N
+18,"2007-05-01","10:30:20","crit.example.com",\N,100,\N,\N
+19,"2007-04-30","10:30:20","alert.example.com",\N,101,\N,\N
+20,"2007-05-01","10:30:20","emerg.example.com",\N,102,\N,\N
+21,"2007-04-30","10:30:20","emerg.example.com",\N,103,\N,\N
+22,"2007-04-30","10:30:20","debug.example.com",\N,104,\N,\N
+23,"2007-04-30","10:30:20","notice.example.com",\N,105,\N,\N
+24,"2007-05-01","10:30:20","crit.example.com",\N,106,\N,\N
+25,"2007-04-30","10:30:20","debug.example.com",\N,107,\N,\N
+26,"2007-04-30","10:30:20","info.example.com",\N,108,\N,\N
+27,"2007-05-01","10:30:20","notice.example.com",\N,109,\N,\N
+28,"2007-04-30","10:30:20","err.example.com",\N,110,\N,\N
+29,"2007-05-01","10:30:20","err.example.com",\N,111,\N,\N
+30,"2007-05-01","10:30:20","alert.example.com",\N,112,\N,\N
+31,"2007-04-30","10:30:20","alert.example.com",\N,113,\N,\N
+32,"2007-05-01","10:30:20","emerg.example.com",\N,114,\N,\N
+33,"2007-04-30","10:30:20","crit.example.com",\N,115,\N,\N
+34,"2007-05-01","10:30:20","info.example.com",\N,116,\N,\N
+35,"2007-05-01","10:30:20","debug.example.com",\N,117,\N,\N
+36,"2007-04-30","10:30:20","debug.example.com",\N,118,\N,\N
+37,"2007-04-30","10:30:20","err.example.com",\N,119,\N,\N
+38,"2007-04-30","10:30:20","warning.example.com",\N,120,\N,\N
+39,"2007-04-30","10:30:20","emerg.example.com",\N,121,\N,\N
+40,"2007-05-01","10:30:20","warning.example.com",\N,122,\N,\N
+41,"2007-05-01","10:30:20","info.example.com",\N,123,\N,\N
+42,"2007-05-01","10:30:20","alert.example.com",\N,124,\N,\N
+43,"2007-04-30","10:30:20","warning.example.com",\N,125,\N,\N
+44,"2007-05-01","10:30:20","debug.example.com",\N,126,\N,\N
+45,"2007-04-30","10:30:20","emerg.example.com",\N,127,\N,\N
+46,"2007-05-01","10:30:20","emerg.example.com",\N,128,\N,\N
+47,"2007-05-01","10:30:20","alert.example.com",\N,129,\N,\N
+48,"2007-04-30","10:30:20","info.example.com",\N,130,\N,\N
+49,"2007-05-01","10:30:20","crit.example.com",\N,131,\N,\N
+50,"2007-05-01","10:30:20","info.example.com",\N,132,\N,\N
+51,"2007-04-30","10:30:20","notice.example.com",\N,133,\N,\N
+52,"2007-05-01","10:30:20","info.example.com",\N,134,\N,\N
+53,"2007-05-01","10:30:20","warning.example.com",\N,135,\N,\N
+54,"2007-05-01","10:30:20","emerg.example.com",\N,136,\N,\N
+55,"2007-05-01","10:30:20","debug.example.com",\N,137,\N,\N
+56,"2007-05-01","10:30:20","alert.example.com",\N,138,\N,\N
+57,"2007-04-30","10:30:20","crit.example.com",\N,139,\N,\N
+58,"2007-04-30","10:30:20","emerg.example.com",\N,140,\N,\N
+59,"2007-04-30","10:30:20","notice.example.com",\N,141,\N,\N
+60,"2007-04-30","10:30:20","crit.example.com",\N,142,\N,\N
+61,"2007-04-30","10:30:20","info.example.com",\N,143,\N,\N
+62,"2007-04-30","10:30:20","info.example.com",\N,144,\N,\N
+63,"2007-04-30","10:30:20","debug.example.com",\N,145,\N,\N
+64,"2007-05-01","10:30:20","crit.example.com",\N,146,\N,\N
+65,"2007-04-30","10:30:20","alert.example.com",\N,147,\N,\N
+66,"2007-04-30","10:30:20","warning.example.com",\N,148,\N,\N
+67,"2007-05-01","10:30:20","warning.example.com",\N,149,\N,\N
+68,"2007-05-01","10:30:20","err.example.com",\N,150,\N,\N
+69,"2007-05-01","10:30:20","notice.example.com",\N,151,\N,\N
+70,"2007-05-01","10:30:20","notice.example.com",\N,152,\N,\N
+71,"2007-04-30","10:30:20","info.example.com",\N,153,\N,\N
+72,"2007-05-01","10:30:20","err.example.com",\N,154,\N,\N
+73,"2007-04-30","10:30:20","alert.example.com",\N,155,\N,\N
+74,"2007-05-01","10:30:20","crit.example.com",\N,156,\N,\N
+75,"2007-05-01","10:30:20","alert.example.com",\N,157,\N,\N
+76,"2007-05-01","10:30:20","info.example.com",\N,158,\N,\N
+77,"2007-04-30","10:30:20","warning.example.com",\N,159,\N,\N
+78,"2007-04-30","10:30:20","crit.example.com",\N,160,\N,\N
+79,"2007-05-01","10:30:20","notice.example.com",\N,161,\N,\N
+80,"2007-04-30","10:30:20","notice.example.com",\N,162,\N,\N

Added: incubator/alois/trunk/prisma/test/fixtures/messages.csv
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/messages.csv?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/messages.csv (added)
+++ incubator/alois/trunk/prisma/test/fixtures/messages.csv Thu Nov  4 18:27:22 2010
@@ -0,0 +1,81 @@
+id,meta_id,msg,meta_type_name
+1,1,"log_yesterday_warning_user","Prisma::LogMeta"
+2,2,"log_today_debug_mail","Prisma::LogMeta"
+3,3,"log_today_err_mail","Prisma::LogMeta"
+4,4,"log_yesterday_alert_mail","Prisma::LogMeta"
+5,5,"log_today_emerg_mail","Prisma::LogMeta"
+6,6,"log_yesterday_emerg_mail","Prisma::LogMeta"
+7,7,"log_yesterday_debug_mail","Prisma::LogMeta"
+8,8,"log_today_warning_system","Prisma::LogMeta"
+9,9,"log_yesterday_crit_system","Prisma::LogMeta"
+10,10,"log_today_warning_user","Prisma::LogMeta"
+11,11,"log_today_notice_mail","Prisma::LogMeta"
+12,12,"log_yesterday_err_mail","Prisma::LogMeta"
+13,13,"log_today_err_system","Prisma::LogMeta"
+14,14,"log_yesterday_err_kernel","Prisma::LogMeta"
+15,15,"log_today_debug_auth","Prisma::LogMeta"
+16,16,"log_yesterday_notice_auth","Prisma::LogMeta"
+17,17,"log_yesterday_err_system","Prisma::LogMeta"
+18,18,"log_today_crit_user","Prisma::LogMeta"
+19,19,"log_yesterday_alert_auth","Prisma::LogMeta"
+20,20,"log_today_emerg_auth","Prisma::LogMeta"
+21,21,"log_yesterday_emerg_auth","Prisma::LogMeta"
+22,22,"log_yesterday_debug_auth","Prisma::LogMeta"
+23,23,"log_yesterday_notice_kernel","Prisma::LogMeta"
+24,24,"log_today_crit_system","Prisma::LogMeta"
+25,25,"log_yesterday_debug_kernel","Prisma::LogMeta"
+26,26,"log_yesterday_info_kernel","Prisma::LogMeta"
+27,27,"log_today_notice_auth","Prisma::LogMeta"
+28,28,"log_yesterday_err_auth","Prisma::LogMeta"
+29,29,"log_today_err_auth","Prisma::LogMeta"
+30,30,"log_today_alert_user","Prisma::LogMeta"
+31,31,"log_yesterday_alert_user","Prisma::LogMeta"
+32,32,"log_today_emerg_user","Prisma::LogMeta"
+33,33,"log_yesterday_crit_user","Prisma::LogMeta"
+34,34,"log_today_info_mail","Prisma::LogMeta"
+35,35,"log_today_debug_kernel","Prisma::LogMeta"
+36,36,"log_yesterday_debug_system","Prisma::LogMeta"
+37,37,"log_yesterday_err_user","Prisma::LogMeta"
+38,38,"log_yesterday_warning_kernel","Prisma::LogMeta"
+39,39,"log_yesterday_emerg_kernel","Prisma::LogMeta"
+40,40,"log_today_warning_mail","Prisma::LogMeta"
+41,41,"log_today_info_kernel","Prisma::LogMeta"
+42,42,"log_today_alert_kernel","Prisma::LogMeta"
+43,43,"log_yesterday_warning_system","Prisma::LogMeta"
+44,44,"log_today_debug_system","Prisma::LogMeta"
+45,45,"log_yesterday_emerg_system","Prisma::LogMeta"
+46,46,"log_today_emerg_kernel","Prisma::LogMeta"
+47,47,"log_today_alert_system","Prisma::LogMeta"
+48,48,"log_yesterday_info_mail","Prisma::LogMeta"
+49,49,"log_today_crit_mail","Prisma::LogMeta"
+50,50,"log_today_info_auth","Prisma::LogMeta"
+51,51,"log_yesterday_notice_user","Prisma::LogMeta"
+52,52,"log_today_info_user","Prisma::LogMeta"
+53,53,"log_today_warning_auth","Prisma::LogMeta"
+54,54,"log_today_emerg_system","Prisma::LogMeta"
+55,55,"log_today_debug_user","Prisma::LogMeta"
+56,56,"log_today_alert_mail","Prisma::LogMeta"
+57,57,"log_yesterday_crit_kernel","Prisma::LogMeta"
+58,58,"log_yesterday_emerg_user","Prisma::LogMeta"
+59,59,"log_yesterday_notice_system","Prisma::LogMeta"
+60,60,"log_yesterday_crit_mail","Prisma::LogMeta"
+61,61,"log_yesterday_info_system","Prisma::LogMeta"
+62,62,"log_yesterday_info_auth","Prisma::LogMeta"
+63,63,"log_yesterday_debug_user","Prisma::LogMeta"
+64,64,"log_today_crit_auth","Prisma::LogMeta"
+65,65,"log_yesterday_alert_kernel","Prisma::LogMeta"
+66,66,"log_yesterday_warning_mail","Prisma::LogMeta"
+67,67,"log_today_warning_kernel","Prisma::LogMeta"
+68,68,"log_today_err_user","Prisma::LogMeta"
+69,69,"log_today_notice_kernel","Prisma::LogMeta"
+70,70,"log_today_notice_user","Prisma::LogMeta"
+71,71,"log_yesterday_info_user","Prisma::LogMeta"
+72,72,"log_today_err_kernel","Prisma::LogMeta"
+73,73,"log_yesterday_alert_system","Prisma::LogMeta"
+74,74,"log_today_crit_kernel","Prisma::LogMeta"
+75,75,"log_today_alert_auth","Prisma::LogMeta"
+76,76,"log_today_info_system","Prisma::LogMeta"
+77,77,"log_yesterday_warning_auth","Prisma::LogMeta"
+78,78,"log_yesterday_crit_auth","Prisma::LogMeta"
+79,79,"log_today_notice_system","Prisma::LogMeta"
+80,80,"log_yesterday_notice_mail","Prisma::LogMeta"

Added: incubator/alois/trunk/prisma/test/fixtures/source_db_metas.csv
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/source_db_metas.csv?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/source_db_metas.csv (added)
+++ incubator/alois/trunk/prisma/test/fixtures/source_db_metas.csv Thu Nov  4 18:27:22 2010
@@ -0,0 +1,4 @@
+id, process_type, start, current, total, todo, count, raw_class_name, execute_once, waiting_time, finished, created_at, updated_at
+1,"--- :lasts",\N,\N,0,\N,100,"Prisma::SyslogdRaw",0,2,1,"2007-04-30 22:18:34","2007-04-30 22:18:34"
+2,\N,\N,\N,\N,\N,\N,\N,\N,\N,0,"2007-04-30 22:18:34","2007-04-30 22:18:34"
+3,"--- :lasts",721,721,80,0,100,"Prisma::SyslogdRaw",0,2,1,"2007-04-30 22:18:40","2007-04-30 22:19:52"

Added: incubator/alois/trunk/prisma/test/fixtures/squid_metas.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/squid_metas.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/squid_metas.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/squid_metas.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,33 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+  process_id: 1
+  seconds_since_epoch: 1
+  subsecond_time: 1
+  response_time_milliseconds: 1
+  client_source_ip: MyString
+  request_status: MyString
+  http_status_code: 1
+  reply_size: 1
+  request_method: MyString
+  request_url: MyString
+  user_name: MyString
+  hierarchy_status: MyString
+  client_fqdn: MyString
+  mime_type: MyString
+
+two:
+  process_id: 1
+  seconds_since_epoch: 1
+  subsecond_time: 1
+  response_time_milliseconds: 1
+  client_source_ip: MyString
+  request_status: MyString
+  http_status_code: 1
+  reply_size: 1
+  request_method: MyString
+  request_url: MyString
+  user_name: MyString
+  hierarchy_status: MyString
+  client_fqdn: MyString
+  mime_type: MyString

Added: incubator/alois/trunk/prisma/test/fixtures/syslogd_metas.csv
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/syslogd_metas.csv?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/syslogd_metas.csv (added)
+++ incubator/alois/trunk/prisma/test/fixtures/syslogd_metas.csv Thu Nov  4 18:27:22 2010
@@ -0,0 +1,82 @@
+id,ip,facility,level,tag,program,archive_metas_id,source_db_metas_id
+1,"192.168.123.123","user","warning","warning","0",0,1
+2,"192.168.123.123","user","warning","warning","0",0,3
+3,"192.168.123.123","mail","debug","debug","0",0,3
+4,"192.168.123.123","mail","err","err","0",0,3
+5,"192.168.123.123","mail","alert","alert","0",0,3
+6,"192.168.123.123","mail","emerg","emerg","0",0,3
+7,"192.168.123.123","mail","emerg","emerg","0",0,3
+8,"192.168.123.123","mail","debug","debug","0",0,3
+9,"192.168.123.123","system","warning","warning","0",0,3
+10,"192.168.123.123","system","crit","crit","0",0,3
+11,"192.168.123.123","user","warning","warning","0",0,3
+12,"192.168.123.123","mail","notice","notice","0",0,3
+13,"192.168.123.123","mail","err","err","0",0,3
+14,"192.168.123.123","system","err","err","0",0,3
+15,"192.168.123.123","kernel","err","err","0",0,3
+16,"192.168.123.123","auth","debug","debug","0",0,3
+17,"192.168.123.123","auth","notice","notice","0",0,3
+18,"192.168.123.123","system","err","err","0",0,3
+19,"192.168.123.123","user","crit","crit","0",0,3
+20,"192.168.123.123","auth","alert","alert","0",0,3
+21,"192.168.123.123","auth","emerg","emerg","0",0,3
+22,"192.168.123.123","auth","emerg","emerg","0",0,3
+23,"192.168.123.123","auth","debug","debug","0",0,3
+24,"192.168.123.123","kernel","notice","notice","0",0,3
+25,"192.168.123.123","system","crit","crit","0",0,3
+26,"192.168.123.123","kernel","debug","debug","0",0,3
+27,"192.168.123.123","kernel","info","info","0",0,3
+28,"192.168.123.123","auth","notice","notice","0",0,3
+29,"192.168.123.123","auth","err","err","0",0,3
+30,"192.168.123.123","auth","err","err","0",0,3
+31,"192.168.123.123","user","alert","alert","0",0,3
+32,"192.168.123.123","user","alert","alert","0",0,3
+33,"192.168.123.123","user","emerg","emerg","0",0,3
+34,"192.168.123.123","user","crit","crit","0",0,3
+35,"192.168.123.123","mail","info","info","0",0,3
+36,"192.168.123.123","kernel","debug","debug","0",0,3
+37,"192.168.123.123","system","debug","debug","0",0,3
+38,"192.168.123.123","user","err","err","0",0,3
+39,"192.168.123.123","kernel","warning","warning","0",0,3
+40,"192.168.123.123","kernel","emerg","emerg","0",0,3
+41,"192.168.123.123","mail","warning","warning","0",0,3
+42,"192.168.123.123","kernel","info","info","0",0,3
+43,"192.168.123.123","kernel","alert","alert","0",0,3
+44,"192.168.123.123","system","warning","warning","0",0,3
+45,"192.168.123.123","system","debug","debug","0",0,3
+46,"192.168.123.123","system","emerg","emerg","0",0,3
+47,"192.168.123.123","kernel","emerg","emerg","0",0,3
+48,"192.168.123.123","system","alert","alert","0",0,3
+49,"192.168.123.123","mail","info","info","0",0,3
+50,"192.168.123.123","mail","crit","crit","0",0,3
+51,"192.168.123.123","auth","info","info","0",0,3
+52,"192.168.123.123","user","notice","notice","0",0,3
+53,"192.168.123.123","user","info","info","0",0,3
+54,"192.168.123.123","auth","warning","warning","0",0,3
+55,"192.168.123.123","system","emerg","emerg","0",0,3
+56,"192.168.123.123","user","debug","debug","0",0,3
+57,"192.168.123.123","mail","alert","alert","0",0,3
+58,"192.168.123.123","kernel","crit","crit","0",0,3
+59,"192.168.123.123","user","emerg","emerg","0",0,3
+60,"192.168.123.123","system","notice","notice","0",0,3
+61,"192.168.123.123","mail","crit","crit","0",0,3
+62,"192.168.123.123","system","info","info","0",0,3
+63,"192.168.123.123","auth","info","info","0",0,3
+64,"192.168.123.123","user","debug","debug","0",0,3
+65,"192.168.123.123","auth","crit","crit","0",0,3
+66,"192.168.123.123","kernel","alert","alert","0",0,3
+67,"192.168.123.123","mail","warning","warning","0",0,3
+68,"192.168.123.123","kernel","warning","warning","0",0,3
+69,"192.168.123.123","user","err","err","0",0,3
+70,"192.168.123.123","kernel","notice","notice","0",0,3
+71,"192.168.123.123","user","notice","notice","0",0,3
+72,"192.168.123.123","user","info","info","0",0,3
+73,"192.168.123.123","kernel","err","err","0",0,3
+74,"192.168.123.123","system","alert","alert","0",0,3
+75,"192.168.123.123","kernel","crit","crit","0",0,3
+76,"192.168.123.123","auth","alert","alert","0",0,3
+77,"192.168.123.123","system","info","info","0",0,3
+78,"192.168.123.123","auth","warning","warning","0",0,3
+79,"192.168.123.123","auth","crit","crit","0",0,3
+80,"192.168.123.123","system","notice","notice","0",0,3
+81,"192.168.123.123","mail","notice","notice","0",0,3

Added: incubator/alois/trunk/prisma/test/fixtures/syslogd_raws.yml
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/fixtures/syslogd_raws.yml?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/fixtures/syslogd_raws.yml (added)
+++ incubator/alois/trunk/prisma/test/fixtures/syslogd_raws.yml Thu Nov  4 18:27:22 2010
@@ -0,0 +1,27 @@
+<% i = 0 %>
+<% 
+  DATES = { "today" => Date.today.to_s, "yesterday" => (Date.today - 1).to_s } unless defined?(DATES)
+%>
+
+<%
+SyslogdRaw::LEVELS.each { |level| 
+  SyslogdRaw::FACILITIES.each { |facility|
+    DATES.each { |date_name,date_value|
+
+%>
+
+log_<%= "#{date_name}_#{level}_#{facility}" %>:
+ id: <%= i += 1 %>
+ ip: "192.168.123.123"
+ host: "<%= level %>.example.com"
+ facility: "<%= facility %>"
+ priority: "<%= level %>"
+ level: "<%= level %>"
+ tag: "0" 
+ date: <%= date_value %> 
+ time: "10:30:20"
+ program: "0"
+ created_at: NULL
+ msg: "<%= "log_#{date_name}_#{level}_#{facility}" %>"
+ 
+<% } } } %>
\ No newline at end of file

Added: incubator/alois/trunk/prisma/test/test_helper.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/test_helper.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/test_helper.rb (added)
+++ incubator/alois/trunk/prisma/test/test_helper.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,261 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require "libisi"
+init_libisi
+#Log.log_level -= 2
+PRISMA_ENV = "test"
+
+require 'test/unit'
+require File.expand_path(File.dirname(__FILE__) + "/../conf/prisma/environment.rb")
+
+Prisma::Database.load_all
+
+require "active_record/fixtures"
+class PrismaTest < Test::Unit::TestCase
+
+  def insert_fixture(klass)
+    fixture_file = Pathname.new(__FILE__).dirname + "fixtures/" + klass.table_name
+    fix = Fixtures.new(klass.connection_pool.connection,
+                       klass.table_name,
+                       klass.name,
+                       fixture_file) #, file_filter = DEFAULT_FILTER_RE)
+    fix.insert_fixtures
+  end
+
+end
+#require 'test_help'
+=begin
+class ActiveSupport::TestCase
+  # Transactional fixtures accelerate your tests by wrapping each test method
+  # in a transaction that's rolled back on completion.  This ensures that the
+  # test database remains unchanged so your fixtures don't have to be reloaded
+  # between every test method.  Fewer database queries means faster tests.
+  #
+  # Read Mike Clark's excellent walkthrough at
+  #   http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
+  #
+  # Every Active Record database supports transactions except MyISAM tables
+  # in MySQL.  Turn off transactional fixtures in this case; however, if you
+  # don't care one way or the other, switching from MyISAM to InnoDB tables
+  # is recommended.
+  #
+  # The only drawback to using transactional fixtures is when you actually 
+  # need to test transactions.  Since your test is bracketed by a transaction,
+  # any transactions started in your code will be automatically rolled back.
+  self.use_transactional_fixtures = true #false
+
+  # Instantiated fixtures are slow, but give you @david where otherwise you
+  # would need people(:david).  If you don't want to migrate your existing
+  # test cases which use the @david style and don't mind the speed hit (each
+  # instantiated fixtures translates to a database query per test method),
+  # then set this back to true.
+  self.use_instantiated_fixtures  = false
+
+  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+  #
+  # Note: You'll currently still have to declare fixtures explicitly in integration tests
+  # -- they do not yet inherit this setting
+  fixtures :all
+
+  # Add more helper methods to be used by all tests here...
+
+  # compare yaml, sort first to ensure matching if
+  # some attribtues changed, this is not a 100%
+  # test but should be enough for testing
+  def assert_equal_yaml(yaml1, yaml2, text = nil)
+    assert_equal yaml1.split("\n").sort, yaml2.split("\n").sort, text
+  end
+
+  def self.import_file(file)
+    print "File #{file}.\n"
+    Prisma.transform_file(file,"type=#{File.extname(file)[1..-1]}")
+
+    source = Prisma::SourceDbMeta.new.prisma_initialize(:all, Prisma::FileRaw)
+    source.transform
+  end
+
+  def file_info(filename)
+    basename = Pathname.new(filename).basename.to_s
+    unless basename =~ /([^\.]*)\.(.*)/
+      g = Dir.glob(filename + ".*").reject {|f| f =~ /\~$/ or f=~/\..*\./}
+      throw "More than one file found. (#{g.inspect})" if g.length > 1
+      throw "File not found '#{filename + ".*"}'" if g.length == 0
+      filename = g[0]
+    end
+    basename = Pathname.new(filename).basename.to_s
+    throw "Malformed filename '#{filename}'" unless basename =~ /([^\.]*)\.(.*)/
+    table_name, type = $1,$2
+    table_class = Prisma.get_class_from_tablename(table_name)
+    throw "Table '#{table_name}' not found." unless table_class
+    
+    ret = {:type => type, :table_class => table_class, :filename => filename}
+  end
+
+  def load_file(filename)
+    fi = file_info(filename)
+    table_class = fi[:table_class]
+
+    case fi[:type]
+    when "messages"
+      Message.delete_all
+      msgs = []
+      for line in open(fi[:filename])
+	# correct windows linefeeds
+	line = line[0..-3] + "\n" if line.ends_with?("\r\n")
+
+	parent = table_class.new
+	message = Message.new.prisma_initialize(parent,line)
+	message.save
+	msgs.push message
+      end
+      return msgs
+    when "archive"
+      a = ArchiveMeta.new.prisma_initialize(fi[:filename])
+      a.save            
+      return a
+    else
+      throw "unknown type '#{type}'."
+    end
+  end
+
+  def load_and_transform_file(filename, expected_message_count = 0)
+    fi = file_info(filename)
+    Message.delete_all
+    fi[:table_class].delete_all
+
+    ret = load_file(filename)
+    Prisma.transform_messages
+    if Message.count > 0
+      Message.find(:all).each {|m|
+	p m.msg
+      }
+      print "Found still #{Message.count} messages.\n"
+    end
+    assert_equal expected_message_count, Message.count
+  end
+
+  # from http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabasesWithFixtures
+  
+  cattr_accessor :classes_cache
+  #class cache for storing already founded classes from models
+  @@classes_cache = {}
+
+  def table_names_and_classes(table_names)
+    table_names = table_names.flatten.collect{|t| t.to_s}
+    tables = table_names.map {|table_name|
+      unless @@classes_cache[table_name].nil?
+        klass = @@classes_cache[table_name]
+      else
+        begin 
+          #try to find class name from table name
+          klass = eval(table_name.classify)
+        rescue
+          #go to model directory, run through all models and search for table name
+          classes = Dir.entries(RAILS_ROOT + "/app/models").select{|d| d.include?(".rb")}.collect{|f| File.basename(f, ".rb").classify}
+          klass_names = classes.select{|f| (eval("#{f}.table_name") rescue false)==table_name }
+          klass_name = klass_names.blank? ? table_name.classify : klass_names.first
+          klass = eval(klass_name)
+        end
+        @@classes_cache[table_name] = klass
+      end
+      [table_name, klass]
+    }
+  end
+
+
+  def load_user_fixtures(*table_names)
+    tables = table_names_and_classes(table_names)
+
+    # clear tables
+    tables.each {|table_name,klass|
+      klass.delete_all
+    }
+
+    tables.each {|table_name, klass|
+      fs = Dir.glob(File.dirname(__FILE__) + "/fixtures_*").map {|f_path|
+	fix = Fixtures.new(klass.connection, 
+			   klass.table_name,
+			   klass.name,
+			   f_path + "/" + klass.table_name) #, file_filter = DEFAULT_FILTER_RE)
+	fix.insert_fixtures
+      }
+    }
+
+    # check if fixtures are loaded
+    tables.each {|table_name,klass|
+      raise "Fixtures of class #{klass.name} not loaded"if klass.count == 0
+    }
+  end
+    
+
+  #  CHART_YAML =  "--- !ruby/object:Chart \nattributes: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\n"
+  #  CHART_YAML =  "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: \"0\"\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  aggregation_function: COUNT\n  width: \"300\"\n  column2: time\n"
+  CHART_YAML =  "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  flipped: f\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: f\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\n"
+  
+  CHART_QUERY = "SELECT date, time, COUNT(date) AS data FROM application_logs WHERE `date` = '2008-04-09'  GROUP BY time, date ORDER BY date, time"
+  
+  CHART_RENDER_OPTIONS = {:conditions => "1=1", :datasource => ApplicationLog}
+  
+  #  CHART_AFTER_RENDER_YAML = "--- !ruby/object:Chart \nattributes: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\nexternal_link: http://localhost:3001/alois/table/application_logs/chart_click?default_filter=%60date%60+%3D+%272008-04-09%27++AND+1%3D1&\noption_conditions: 1=1\ntable_name: application_logs\n"
+  #  CHART_AFTER_RENDER_YAML = "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: \"0\"\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  aggregation_function: COUNT\n  width: \"300\"\n  column2: time\nexternal_link: https://localhost:3001/alois/table/application_logs/chart_click?default_filter=%60date%60+%3D+%272008-04-09%27++AND+1%3D1&\noption_conditions: 1=1\ntable_name: application_logs\n"  
+  CHART_AFTER_RENDER_YAML = "--- !ruby/object:Chart \nattributes: \n  column3: \n  time_range: \"2008-04-09\"\n  name: Date Test Bars\n  flipped: f\n  chart_type: bars\n  id: \"1\"\n  description: For date report testing\n  stacked: f\n  max_values: \"45\"\n  height: \"300\"\n  order_by: \n  aggregation_column: date\n  column1: date\n  width: \"300\"\n  aggregation_function: COUNT\n  column2: time\nexternal_link: https://localhost:3001/alois/table/application_logs/chart_click?default_filter=%60date%60+%3D+%272008-04-09%27++AND+1%3D1&\noption_conditions: 1=1\ntable_name: application_logs\n"
+
+
+  def self.test_chart
+    c = Chart.find(:first)
+    c.datasource = ApplicationLog
+    c
+  end
+
+  def save_email(mail, name)
+    file = "#{RAILS_ROOT}/tmp/#{name}.eml"
+    open("#{file}","w") {|f| f.write(mail.encoded)}
+    print "Email saved to '#{file}'.\n"
+    if false
+      print "Starting kmail..."
+      system " kmail --view '#{file}'\n"    
+      print "done\n"
+    end
+    print "Check it in thunderbird.\n"
+    print "/!\\ Thunderbird does not display inline pictures if\n"
+    print "/!\\ the message is saved on disk."
+  end
+  def email_body(part)
+    # or something with that? TMail::Base64.folding_encode(body)
+    (part.body + part.parts.map {|p| email_body(p)}.join).gsub("=\n","").gsub("=3D","=")
+  end
+
+  def check_links_in_email(mail)
+    assert !(mail.body =~ /href=\"(\/[^\"]*)\"/), "Link without domain found '#{$1}'! (href=\"/), maybe you forgegotten option , :only_path => false in link_to."
+  end
+  
+  def assert_tidy_html
+    tidy_command = "tidy -errors -quiet"
+    open("|#{tidy_command} 2>&1 > /dev/null","w") {|f|
+      f.write(@response.body)
+    }
+    if $?.to_i != 0
+      @response.body.split("\n").each_with_index{|l,i|
+	print "#{(i+1).to_s.rjust(3)}: #{l}\n"
+      }
+    end
+    open("|#{tidy_command} > /dev/null","w") {|f|
+      f.write(@response.body)
+    }
+    assert_equal 0,$?.to_i,"Tidy is not happy with the html output."
+  end
+
+end
+=end

Added: incubator/alois/trunk/prisma/test/unit/file_meta_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/unit/file_meta_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/unit/file_meta_test.rb (added)
+++ incubator/alois/trunk/prisma/test/unit/file_meta_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,31 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class SentinelsTest < ActiveSupport::TestCase
+  fixtures :file_metas
+
+  def test_options
+    f = FileMeta.find(1)
+    assert "log", f.filetype
+
+    f = FileMeta.find(2)
+    assert "xyz", f.read_option("a")
+    assert "zyx", f.read_option("b")
+    assert "syslog", f.filetype
+  
+  end
+
+end

Added: incubator/alois/trunk/prisma/test/unit/file_raws_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/unit/file_raws_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/unit/file_raws_test.rb (added)
+++ incubator/alois/trunk/prisma/test/unit/file_raws_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,72 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PrismaTest < ActiveSupport::TestCase
+  ARCH_DIR = "#{RAILS_ROOT}/tmp/archive/test/prisma/"
+  LOG_FILE = "#{RAILS_ROOT}/log/FileRaw.log"
+  
+  def setup
+    [FileRaw, SourceDbMeta,FileMeta,PureMeta,LogMeta,Message,CronMeta].each {|k|
+      k.delete_all
+    }
+    load_user_fixtures :file_raws
+    FileUtils.remove_dir(ARCH_DIR) if File.exist?(ARCH_DIR)
+    File.delete(LOG_FILE) if File.exist?(LOG_FILE)
+  end
+
+  def test_file_size
+    FileRaw.delete_all
+    kbytes = 1024
+    file = "/tmp/alois-big-test-file.log"
+    system("dd if=/dev/urandom of=#{file} bs=1024 count=#{kbytes} 2>/dev/null")
+    Prisma.transform_file(file, :type => "log")
+    assert_equal 1, FileRaw.count
+    raw = FileRaw.find(:first)
+    assert_equal 1024 * kbytes, raw["msg"].length
+    assert_equal 1024 * kbytes, raw.msg.length
+  end
+
+  def test_file_import
+    assert_equal 1, FileRaw.count()
+    assert_equal 0, FileMeta.count()
+    assert_equal 0, SourceDbMeta.count()
+    
+    $alois_disabled_transaction = true
+    Prisma.transform_all_raws(FileRaw)
+    
+    assert_equal 0, FileRaw.count()
+    #p SourceDbMeta.find(:all).each {|s| p s}
+#    p SourceDbMeta.connection.select_value("SELECT count(*) FROM source_db_metas")
+
+    assert_equal 1, SourceDbMeta.count()
+    assert_equal 1, FileMeta.count()
+    assert_equal 6, PureMeta.count()
+    assert_equal 6, LogMeta.count()
+    assert_equal 5, Message.count()
+    assert_equal 5, Message.count(:conditions => "meta_type_name = 'Prisma::LogMeta'")
+
+    m = CronMeta.find(:first)
+    5.times {
+      assert m
+      m = m.parent
+    }
+    assert m.nil?
+    
+    
+#    assert_equal 1, ApacheFileMeta.count()
+#    assert_equal 100, ApacheMeta.count()
+  end
+end

Added: incubator/alois/trunk/prisma/test/unit/inet_header_meta_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/unit/inet_header_meta_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/unit/inet_header_meta_test.rb (added)
+++ incubator/alois/trunk/prisma/test/unit/inet_header_meta_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,24 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class InetHeaderMetaTest < ActiveSupport::TestCase
+  fixtures :inet_header_metas
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

Added: incubator/alois/trunk/prisma/test/unit/inet_object_meta_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/unit/inet_object_meta_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/unit/inet_object_meta_test.rb (added)
+++ incubator/alois/trunk/prisma/test/unit/inet_object_meta_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,28 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class InetObjectMetaTest < ActiveSupport::TestCase
+  fixtures :inet_object_metas
+
+  # Replace this with your real tests.
+  def test_convert
+    assert_equal "abcdüefg",WindowsEventMeta.convert_to_unicode("abcd37777777774efg")
+    ["abcd37777777774efg",
+      "abcd37777777744efg"].each {|s|
+      assert_equal s, WindowsEventMeta.convert_to_wincode(WindowsEventMeta.convert_to_unicode(s.dup))
+    }
+  end
+end

Added: incubator/alois/trunk/prisma/test/unit/prisma_test.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/test/unit/prisma_test.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/prisma/test/unit/prisma_test.rb (added)
+++ incubator/alois/trunk/prisma/test/unit/prisma_test.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,318 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PrismaTest < Test::Unit::TestCase
+  # because some transactions are needed in this test
+  
+  LOG_FILE = PRISMA_LOG_DIR + "SyslogdRaw.log"
+
+  def setup
+    SyslogdRaw.delete_all
+    FileRaw.delete_all
+#    load_user_fixtures :syslogd_raws
+    FileUtils.remove_dir(PRISMA_ARCHIVE) if PRISMA_ARCHIVE.exist?
+    File.delete(LOG_FILE) if File.exist?(LOG_FILE)
+  end
+
+  GENERATE_OUTPUT = false
+
+  def test_signal_term
+    # generate random data to process
+    p "Generate data" if GENERATE_OUTPUT 
+    Prisma::Util.generate_random_raws(200)
+    p "done" if GENERATE_OUTPUT 
+    count = SyslogdRaw.count
+# fp was 200
+    assert count >= 20, "No test data generated... ??"
+    
+    pid = fork do
+      exec("bin/prisma start SyslogdRaw -f -c 10 -v")
+    end
+    
+    p "prisma started" if GENERATE_OUTPUT 
+
+    start_timeout = 20
+    begin      
+      # Wait until prisma started
+      Timeout.timeout(start_timeout) {
+        new_count = SyslogdRaw.count
+	while new_count == count
+          new_count = SyslogdRaw.count
+	  print "Wait for prisma start #{new_count} == #{count}.\n" if GENERATE_OUTPUT 
+	  sleep 1
+	end
+      }
+    rescue Timeout::Error
+      # kill all prisma processes
+      system("pkill -KILL prisma")
+      assert false, "Prisma had more than #{start_timeout} seconds to start."
+    end
+    p "OK, started, so kill" if GENERATE_OUTPUT 
+
+    # ok, prisma is running now. Sending signal term
+    Process.kill("TERM", pid)
+
+    kill_timeout = 3
+    begin
+      # Prisma should return in one second
+      Timeout.timeout(kill_timeout) {
+	p "going to wait" if GENERATE_OUTPUT 
+	Process.waitpid(pid)
+	p "Returned" if GENERATE_OUTPUT 
+      }
+    rescue Timeout::Error
+      p "timeout" if GENERATE_OUTPUT 
+      # kill all prisma processes
+      system("pkill -KILL prisma")
+      assert false, "Prisma had more than #{kill_timeout} second(s)."
+    end
+
+    p "check kill prisma" if GENERATE_OUTPUT 
+    assert(!system("pkill -KILL prisma"), "Oups, there were still prisma processes running.")
+
+    p "assert last" if GENERATE_OUTPUT 
+    # ok prisma returned normally
+    assert(SyslogdRaw.count > 0, "Prisma processed all raws. Increment raw count. Test not evident.")
+
+    assert File.exist?(LOG_FILE), "#{LOG_FILE} was not written."
+    
+  end
+
+  def find_original(meta, orig)
+    assert meta
+    assert (found = meta.original)
+    assert found.class != String, "Error finding orig: #{found}"
+    assert_equal 1, found.length, "Original not found"
+    assert_equal orig, found[0]
+   
+  end
+  
+  def test_find_original
+    SyslogdRaw.delete_all
+    SyslogdMeta.delete_all
+    LogMeta.delete_all
+    orig = SyslogdRaw.create_random_test_message    
+    assert orig
+    assert_equal Date.today.strftime("%F"), orig.date.strftime("%F")
+    Prisma::Transform.transform_all_raws(SyslogdRaw)
+    assert_equal 1, SyslogdMeta.count
+    assert (sm = SyslogdMeta.find(:first))
+    assert_equal orig.id, sm.queue_id
+    assert sm.log_meta
+    assert_equal Date.today.strftime("%F"), sm.log_meta.date.strftime("%F")
+
+    # new way
+    find_original(sm, orig)
+    # from log_meta
+    find_original(sm.children_a[0], orig)
+    # old way
+    sm.queue_id = nil
+    find_original(sm, orig)      
+  end
+
+
+  def test_transform_queues    
+    @raw_count = 80
+    LogMeta.delete_all
+    SourceDbMeta.delete_all
+    SyslogdMeta.delete_all
+    Message.delete_all
+    $destroy_calls = 0
+
+    assert_equal 0,SourceDbMeta.count
+    assert_equal 0,SyslogdMeta.count
+    assert_equal 0,LogMeta.count
+    SyslogdRaw.delete_all
+    FileRaw.delete_all
+
+    insert_fixture(SyslogdRaw)
+
+    assert_equal @raw_count,SyslogdRaw.count
+    assert_equal 0,Message.count
+
+    raws_to_reconstruct = [SyslogdRaw.find(:all)[0],SyslogdRaw.find(:all)[13],SyslogdRaw.find(:all)[-1]]
+
+    assert @raw_count > 0    
+    assert_equal SyslogdRaw.count, @raw_count
+
+    ENV['LOG_OUTPUT'] = "stdout"
+    rd, wr = IO.pipe
+    pid = fork do
+      STDOUT.reopen(wr)
+      STDERR.reopen(wr)
+      exec("bin/prisma start SyslogdRaw -f -vv")
+    end
+    
+    counters = {
+      :insert => /INSERT/,
+      :delete => /DELETE/,
+      :select => /SELECT/,
+      :update => /UPDATE/,
+      :commit => /COMMIT/,
+      :show_tables => /SHOW TABLES/
+    }
+    $counts = {}
+    counters.each {|key, regex| $counts[key] = 0}
+    
+    # set this to true uf you want to
+    # see the output
+    $print_all =  false
+    $count_test = false
+    listen_thread = Thread.fork do
+      error = false
+      l = ""
+      while not l =~ /No new record in table syslogd_raws/
+	l = "CHILD #{rd.readline}"	
+	print "ERROR: #{l}\n" if l =~ /error/i and not l =~ /local jump/
+	if (not (l =~ /source_db_metas/ or l =~ /Getting messages/)) and 
+	    (l =~ /DELETE/ or l =~ /INSERT/ or l =~ /UPDATE/ or l=~ /SELECT/ or l=~ /COMMIT/ or l=~ /SHOW TABLES/)
+	  counters.each {|key, regex| $counts[key] += 1 if l =~ regex  }
+	  if l =~ /INSERT/ or l =~ / FROM .*_raws/ or l =~ /COMMIT/ or l =~ /schema_migrations/ or l =~/SHOW TABLES/
+	    print "\e[5;36;1m\e[0m : #{l}" if $print_all
+	  elsif l =~ /SELECT name/
+            # sqlite only, do not count these selects
+            $counts[:select] = $counts[:select] - 1
+          else
+	    print "\e[3;36;1mUNEXPECTED QUERY\e[0m : #{l}\n" 
+	  end
+	else
+	    print "#{l}" if $print_all
+	end
+      end
+
+      counters.each {|key, regex|
+      }
+      print "ERROR: #{error} DELETE: #{$counts[:delete]}(=1) INSERT: #{$counts[:insert]}(=#{@raw_count * 2}) UPDATE: #{$counts[:update]}(=0) SELECT: #{$counts[:select]}(<10) COMMIT: #{$counts[:commit]}(<20) SHOW TABLES: #{$counts[:show_tables]} (??)\n"
+
+      if not error and
+	  $counts[:delete] == 1 and 
+	  $counts[:update] == 0 and 
+	  $counts[:select] < 10 and 
+	  $counts[:commit] < 20 and 
+	  $counts[:insert] == @raw_count * 2
+	$count_test = true
+      end
+    end
+
+    begin
+      Timeout.timeout(60) {
+        listen_thread.join
+      }
+    rescue Timeout::Error
+      Process.kill("KILL",pid)
+      assert false, "Procesling logs had more than 60 seconds!"
+    end        
+    wr.close
+
+    begin
+      Timeout.timeout(10) {
+        Process.kill("TERM",pid)
+      }
+    rescue Timeout::Error
+      Process.kill("KILL",pid)
+      assert false, "Primsa process not killed correctly"
+    end        
+
+    print "Waiting for prisma\n"
+    Process.waitpid(pid)
+
+    prisma_return = $?.exitstatus
+
+
+#    Prisma::Database.check_connections
+
+    # there may be only one delete (raw message delete query)
+    assert_equal 0, prisma_return, "PRISMA did not return with exit 0"
+    
+    # no update inspite of sourcedb update may be done
+    assert $count_test, "Query execution count tests failed. SEE CHECK OUTPUT"
+
+
+    assert_equal 0, SyslogdRaw.count, "Not all raws deleted."
+    assert_equal @raw_count, SyslogdMeta.count, "Syslogd metas not correct created."
+    assert_equal @raw_count, Message.count
+
+    # syslogd raw
+    assert_equal 1,SourceDbMeta.count, "Source db metas not correct created.\n #{SourceDbMeta.find(:all).map(&:inspect).join("\n")}"
+
+#    f = SourceDbMeta.find(:first, :conditions => ["raw_class_name = ?","FileRaw"])
+    s = SourceDbMeta.find(:first, :conditions => ["raw_class_name = ?","SyslogdRaw"])
+   
+#    assert_equal f.raw_class, FileRaw
+    assert_equal s.raw_class, SyslogdRaw
+    
+    i = 0
+    s.children {|ch|
+      i += 1
+      assert_equal ch.class, SyslogdMeta      
+    }
+    assert_equal @raw_count, i
+
+    # has archive been written?
+    arch_file = PRISMA_ARCHIVE + "syslogd_raws/#{Date.today.to_s}/#{(Date.today - 1).to_s}.arch"
+    assert arch_file.exist?, "Archfile '#{arch_file}' was not created!"
+    
+    # maybe include also file import test here?
+    #    arch_file = "#{PRISMA_ARCHIVE}file_raws/#{Date.today.to_s}/#{(Date.today).to_s}.arch"
+    #    assert File.exist?(arch_file), "Archfile '#{arch_file}' was not created!"
+
+    # count lines
+    i=0
+    Dir.glob("#{PRISMA_ARCHIVE}/syslogd_raws/*/*").each {|fn|
+      open(fn) {|f| f.each {|l| i += 1}
+      }}
+    assert_equal @raw_count, i, "Not all or duplicate logs archived."
+      
+
+    # Ensure that syslogd_raw can be refound in archive
+    metas_to_reconstruct = [SyslogdMeta.find(:all)[0],SyslogdMeta.find(:all)[13],SyslogdMeta.find(:all)[-1]]
+    metas_to_reconstruct.each_with_index { |meta,i|
+      # assert_equal meta.original , raws_to_reconstruct[i]
+      orgs = meta.original
+      orgs.each {|o|
+	print "#{o}\n"
+      }
+      assert_equal 1, orgs.length
+      assert_equal orgs[0] , raws_to_reconstruct[i]
+    }
+    
+
+    # Ensure that all records will be deleted
+    p = LogMeta.find(:first)    
+    m = Message.new.prisma_initialize(p,"DO NOT DELETE")
+    assert m.meta_id, p.id
+    m.meta_type_name = "TEST"
+    m.save
+    
+    #ActiveRecord::Base.logger = Logger.new(STDOUT)
+
+    predicted_deletes = SourceDbMeta.count + SourceDbMeta.find(:all).inject(0) {|s,m| s += m.children_recursive.length}
+    Prisma::Database.delete_logs_before(:all,1.days.from_now.strftime("%F"))
+    
+    assert_equal 0,SyslogdRaw.count
+    assert_equal 0,SourceDbMeta.count
+    assert_equal 0,SyslogdMeta.count
+    assert_equal 0,LogMeta.count
+    assert_equal 1,Message.count    
+
+    assert_equal 1 + 3 * @raw_count, $destroy_calls
+    assert_equal predicted_deletes, $destroy_calls
+
+
+    assert_equal 0,Dir.glob("#{PRISMA_ARCHIVE}syslogd_raws/*/*").length
+  end
+
+end



Mime
View raw message