sekka 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
data/emacs/sekka.el CHANGED
@@ -1417,7 +1417,7 @@ point から行頭方向に同種の文字列が続く間を漢字変換しま
1417
1417
  (setq default-input-method "japanese-sekka")
1418
1418
 
1419
1419
  (defconst sekka-version
1420
- "0.8.6" ;;SEKKA-VERSION
1420
+ "0.8.7" ;;SEKKA-VERSION
1421
1421
  )
1422
1422
  (defun sekka-version (&optional arg)
1423
1423
  "入力モード変更"
@@ -179,6 +179,16 @@
179
179
  (obj.open cacheSource)
180
180
  obj)
181
181
  #f)
182
+ ;; 読み書きできるか調べる
183
+ (let ([d (. (Date.new 0) to_s)])
184
+ (if (and (kvs.pure_put! "key_for_ping" d)
185
+ (string=? (kvs.get "key_for_ping") d))
186
+ (STDERR.puts "Info: database file was clean")
187
+ ;; 正常に読み書きできないようであれば、データベースを修復する
188
+ (begin
189
+ (STDERR.puts "Info: database file was NOT clean. try to fix...")
190
+ (kvs.fixdb)
191
+ (STDERR.puts "Info: done."))))
182
192
  (to-arr (list kvs cachesv)))))
183
193
  ;; Export to Ruby world
184
194
  (export-to-ruby openSekkaJisyo)
data/lib/sekka/kvs.rb CHANGED
@@ -1,22 +1,22 @@
1
1
  # kvs.rb - "wrapper library for Key-Value-Store"
2
- #
2
+ #
3
3
  # Copyright (c) 2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
- #
11
+ #
12
12
  # 2. Redistributions in binary form must reproduce the above copyright
13
13
  # notice, this list of conditions and the following disclaimer in the
14
14
  # documentation and/or other materials provided with the distribution.
15
- #
15
+ #
16
16
  # 3. Neither the name of the authors nor the names of its contributors
17
17
  # may be used to endorse or promote products derived from this
18
18
  # software without specific prior written permission.
19
- #
19
+ #
20
20
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
21
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
22
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -28,8 +28,8 @@
28
28
  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
29
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
30
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- #
32
- # $Id:
31
+ #
32
+ # $Id:
33
33
  #
34
34
  require 'tokyocabinet'
35
35
  require 'memcache'
@@ -62,9 +62,22 @@ class Kvs
62
62
  end
63
63
  end
64
64
 
65
+ def fixdb( )
66
+ if not @db.optimize( )
67
+ raise RuntimeError, sprintf( "TokyoCabinet::HDB.optimize error: file=%s", name )
68
+ end
69
+ true
70
+ end
71
+
65
72
  def put!( key, value, timeout = 0 )
73
+ if not self.pure_put!( key, value, timeout )
74
+ raise RuntimeError sprintf( "put! error: key=%s", key.force_encoding("ASCII-8BIT"))
75
+ end
76
+ value
77
+ end
78
+
79
+ def pure_put!( key, value, timeout = 0 )
66
80
  if 0 < key.size
67
- #p "put! " + key + ":" + value
68
81
  case @dbtype
69
82
  when :tokyocabinet
70
83
  @db[ key.force_encoding("ASCII-8BIT") ] = value.force_encoding("ASCII-8BIT")
@@ -74,6 +87,7 @@ class Kvs
74
87
  raise RuntimeError
75
88
  end
76
89
  end
90
+ value
77
91
  end
78
92
 
79
93
  def get( key, fallback = false )
@@ -97,7 +111,7 @@ class Kvs
97
111
  case @dbtype
98
112
  when :tokyocabinet
99
113
  @db.clear
100
- when :memcache
114
+ when :memcache
101
115
  # do nothing
102
116
  else
103
117
  raise RuntimeError
@@ -111,7 +125,7 @@ class Kvs
111
125
  @db.keys.map { |k|
112
126
  k.force_encoding("UTF-8")
113
127
  }
114
- when :memcache
128
+ when :memcache
115
129
  raise RuntimeError, "Kvs#keys method was not implemented for memcache."
116
130
  else
117
131
  raise RuntimeError
@@ -124,7 +138,7 @@ class Kvs
124
138
  @db.fwmkeys( prefix ).each { |k|
125
139
  k.force_encoding("UTF-8")
126
140
  }
127
- when :memcache
141
+ when :memcache
128
142
  raise RuntimeError, "Kvs#forward_match_keys method was not implemented for memcache."
129
143
  else
130
144
  raise RuntimeError
@@ -141,7 +155,7 @@ class Kvs
141
155
  raise RuntimeError
142
156
  end
143
157
  end
144
-
158
+
145
159
  ## for testing
146
160
  def _db()
147
161
  @db
@@ -34,6 +34,8 @@
34
34
  ;;; $Id:
35
35
  ;;;
36
36
  (use srfi-1)
37
+ (use util.list)
38
+ (use util.combinations)
37
39
 
38
40
  ;; 子音が1音だけ入ったテーブル
39
41
  ;; このテーブルはruby-romkan から変換し、一部不足を追加した。
@@ -772,17 +774,6 @@
772
774
  (gen-hiragana->katakana x))
773
775
  (gen-roman->hiragana roman-str roman-method)))
774
776
 
775
- ;; This function port from Gauche-0.9's util.combinations.
776
- (define (cartesian-product lol)
777
- (if (null? lol)
778
- (list '())
779
- (let ((l (car lol))
780
- (rest (cartesian-product (cdr lol))))
781
- (append-map
782
- (lambda (x)
783
- (map (lambda (sub-prod) (cons x sub-prod)) rest))
784
- l))))
785
-
786
777
 
787
778
  (define (patterns->roman-list patterns)
788
779
  (uniq
@@ -1,6 +1,6 @@
1
1
  class SekkaVersion
2
2
  include Singleton
3
3
  def self.version
4
- "0.8.6"
4
+ "0.8.7"
5
5
  end
6
6
  end
data/lib/sekka/util.nnd CHANGED
@@ -33,6 +33,8 @@
33
33
  ;;;
34
34
  ;;; $Id:
35
35
  ;;;
36
+ (use util.list)
37
+
36
38
  (define (string-drop str n)
37
39
  (or (str.slice n (str.size))
38
40
  ""))
@@ -55,10 +57,4 @@
55
57
  (. (line.slice index (line.size)) strip))
56
58
  #f))
57
59
 
58
- (define (take* lst limit)
59
- (let1 len (length lst)
60
- (if (< len limit)
61
- lst
62
- (take lst limit))))
63
-
64
60
 
data/lib/sekkaconfig.rb CHANGED
@@ -2,24 +2,24 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  #
4
4
  # sekkaconfig.rb - "a config info class"
5
- #
5
+ #
6
6
  # Copyright (c) 2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
- #
7
+ #
8
8
  # Redistribution and use in source and binary forms, with or without
9
9
  # modification, are permitted provided that the following conditions
10
10
  # are met:
11
- #
11
+ #
12
12
  # 1. Redistributions of source code must retain the above copyright
13
13
  # notice, this list of conditions and the following disclaimer.
14
- #
14
+ #
15
15
  # 2. Redistributions in binary form must reproduce the above copyright
16
16
  # notice, this list of conditions and the following disclaimer in the
17
17
  # documentation and/or other materials provided with the distribution.
18
- #
18
+ #
19
19
  # 3. Neither the name of the authors nor the names of its contributors
20
20
  # may be used to endorse or promote products derived from this
21
21
  # software without specific prior written permission.
22
- #
22
+ #
23
23
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
24
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
25
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -31,15 +31,15 @@
31
31
  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
32
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
33
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- #
35
- # $Id:
34
+ #
35
+ # $Id:
36
36
  #
37
37
  require 'singleton'
38
38
 
39
39
  module SekkaServer
40
40
  class Config
41
41
  include Singleton
42
-
42
+
43
43
  def self.setup( dictSource, cacheSource = false, listenPort, proxyHost, proxyPort )
44
44
  @@dictSource = dictSource
45
45
  @@cacheSource = cacheSource
@@ -47,11 +47,11 @@ module SekkaServer
47
47
  @@proxyHost = proxyHost
48
48
  @@proxyPort = proxyPort
49
49
  end
50
-
50
+
51
51
  def self.dictSource
52
52
  @@dictSource
53
53
  end
54
-
54
+
55
55
  def self.cacheSource
56
56
  @@cacheSource
57
57
  end
data/lib/sekkaserver.rb CHANGED
@@ -2,24 +2,24 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  #
4
4
  # sekkaserver.rb - "a sekka server"
5
- #
5
+ #
6
6
  # Copyright (c) 2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
- #
7
+ #
8
8
  # Redistribution and use in source and binary forms, with or without
9
9
  # modification, are permitted provided that the following conditions
10
10
  # are met:
11
- #
11
+ #
12
12
  # 1. Redistributions of source code must retain the above copyright
13
13
  # notice, this list of conditions and the following disclaimer.
14
- #
14
+ #
15
15
  # 2. Redistributions in binary form must reproduce the above copyright
16
16
  # notice, this list of conditions and the following disclaimer in the
17
17
  # documentation and/or other materials provided with the distribution.
18
- #
18
+ #
19
19
  # 3. Neither the name of the authors nor the names of its contributors
20
20
  # may be used to endorse or promote products derived from this
21
21
  # software without specific prior written permission.
22
- #
22
+ #
23
23
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
24
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
25
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -31,8 +31,8 @@
31
31
  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
32
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
33
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- #
35
- # $Id:
34
+ #
35
+ # $Id:
36
36
  #
37
37
  require 'rack'
38
38
  require 'nendo'
@@ -83,8 +83,8 @@ module SekkaServer
83
83
  @mutex.synchronize {
84
84
  case command
85
85
  when 'r' # register
86
- dictline =
87
- if 4 == arr.size
86
+ dictline =
87
+ if 4 == arr.size
88
88
  arr[2] + " " + arr[3]
89
89
  else
90
90
  ";; comment"
@@ -127,7 +127,7 @@ module SekkaServer
127
127
  }
128
128
  }
129
129
  end
130
- end
130
+ end
131
131
  }
132
132
  end
133
133
  @thread.run
data/test/henkan-main.nnd CHANGED
@@ -52,7 +52,7 @@
52
52
  ((eq? dbtype 'tokyocabinet)
53
53
  (set! target "./test.tch"))
54
54
  ((eq? dbtype 'memcache)
55
- (set! target "localhost:11211"))
55
+ (error "memcached interface is obsolute."))
56
56
  (else
57
57
  (errorf "Unsupported db type [%s]" (symbol->string dbtype))))
58
58
 
@@ -107,8 +107,7 @@
107
107
  (kvs.open target)
108
108
  (require "tokyocabinet"))
109
109
  ((eq? dbtype 'memcache)
110
- (kvs.open target)
111
- (require "memcache"))
110
+ (error "memcached interface is obsolute."))
112
111
  (else
113
112
  (errorf "Unsupported db type [%s]" (symbol->string dbtype))))
114
113
 
data/test/memcache.nnd ADDED
@@ -0,0 +1,101 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-
2
+ ;;;
3
+ ;;; memcache.nnd - memcacheアクセスのテスト
4
+ ;;;
5
+ ;;; Copyright (c) 2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
6
+ ;;;
7
+ ;;; Redistribution and use in source and binary forms, with or without
8
+ ;;; modification, are permitted provided that the following conditions
9
+ ;;; are met:
10
+ ;;;
11
+ ;;; 1. Redistributions of source code must retain the above copyright
12
+ ;;; notice, this list of conditions and the following disclaimer.
13
+ ;;;
14
+ ;;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;;; notice, this list of conditions and the following disclaimer in the
16
+ ;;; documentation and/or other materials provided with the distribution.
17
+ ;;;
18
+ ;;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;;; may be used to endorse or promote products derived from this
20
+ ;;; software without specific prior written permission.
21
+ ;;;
22
+ ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ ;;;
34
+ ;;; $Id:
35
+ ;;;
36
+ (require "sekka/kvs")
37
+ (use nendo.test)
38
+ (load "./test/common.nnd")
39
+
40
+ (define dbtype 'memcache)
41
+ (define userid "temp")
42
+ (define cachesv (Kvs.new dbtype))
43
+ (cachesv.open "localhost:11211")
44
+
45
+ (test-start "memcached I/F")
46
+ ;;===================================================================
47
+
48
+ ;;-------------------------------------------------------------------
49
+ (test-section "memcached access")
50
+
51
+ (test* "db store 1"
52
+ "one"
53
+ (cachesv.put! "temp::1" "one"))
54
+
55
+ (test* "db fetch 1"
56
+ "one"
57
+ (cachesv.get "temp::1"))
58
+
59
+ (test* "db fetch fallback"
60
+ false
61
+ (cachesv.get "temp::none" false))
62
+
63
+
64
+ ;;-------------------------------------------------------------------
65
+ (test-section "memcached access heavily")
66
+
67
+ (test* "db rw"
68
+ 10000
69
+ (let1 count 0
70
+ (for-each
71
+ (lambda (n)
72
+ (let1 str (sprintf "%06d" n)
73
+ (cachesv.put! (+ "temp::" str) str)
74
+ (when (string=?
75
+ str
76
+ (cachesv.get (+ "temp::" str) str))
77
+ (set! count (+ count 1)))))
78
+ (range 10000))
79
+ count))
80
+
81
+
82
+ (test-section "memcached expire data")
83
+ (test* "db expire time 1"
84
+ "now"
85
+ (cachesv.put! "temp::1" "now" 2))
86
+
87
+ (test* "db expire time 2"
88
+ "now"
89
+ (cachesv.get "temp::1" "now"))
90
+
91
+ (test* "db expire time 3"
92
+ "miss"
93
+ (begin
94
+ (.sleep 3)
95
+ (cachesv.get "temp::1" "miss")))
96
+
97
+
98
+ ;;===================================================================
99
+
100
+
101
+ (test-end)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 6
9
- version: 0.8.6
8
+ - 7
9
+ version: 0.8.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kiyoka Nishiyama
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-13 00:00:00 +09:00
17
+ date: 2011-06-24 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -92,9 +92,9 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  segments:
94
94
  - 0
95
- - 4
95
+ - 5
96
96
  - 1
97
- version: 0.4.1
97
+ version: 0.5.1
98
98
  type: :runtime
99
99
  version_requirements: *id006
100
100
  - !ruby/object:Gem::Dependency
@@ -167,6 +167,7 @@ files:
167
167
  - test/google-ime.nnd
168
168
  - test/henkan-main.nnd
169
169
  - test/jisyo.nnd
170
+ - test/memcache.nnd
170
171
  - test/roman-lib.nnd
171
172
  - test/sharp-number.nnd
172
173
  - test/skk-azik-table.nnd