localmemcache 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/README +5 -2
  2. data/Rakefile +4 -0
  3. data/VERSION +1 -1
  4. data/bench/lmc_bench.rb +1 -1
  5. data/bench/tokyo_cabinet_bench +3 -0
  6. data/bench/tokyo_cabinet_bench.rb +20 -0
  7. data/site/doc/classes/LocalMemCache.html +146 -129
  8. data/site/doc/classes/LocalMemCache.src/M000001.html +1 -1
  9. data/site/doc/classes/LocalMemCache.src/M000002.html +26 -5
  10. data/site/doc/classes/LocalMemCache.src/M000003.html +16 -5
  11. data/site/doc/classes/LocalMemCache.src/M000004.html +7 -23
  12. data/site/doc/classes/LocalMemCache.src/M000005.html +7 -13
  13. data/site/doc/classes/LocalMemCache.src/M000006.html +4 -5
  14. data/site/doc/classes/LocalMemCache.src/M000007.html +6 -5
  15. data/site/doc/classes/LocalMemCache.src/M000008.html +6 -6
  16. data/site/doc/classes/LocalMemCache.src/M000009.html +1 -1
  17. data/site/doc/classes/LocalMemCache.src/M000010.html +4 -6
  18. data/site/doc/classes/LocalMemCache.src/M000011.html +4 -4
  19. data/site/doc/classes/LocalMemCache.src/M000012.html +4 -4
  20. data/site/doc/classes/LocalMemCache/ArgError.html +2 -2
  21. data/site/doc/classes/LocalMemCache/InitError.html +2 -2
  22. data/site/doc/classes/LocalMemCache/LocalMemCacheError.html +2 -2
  23. data/site/doc/classes/LocalMemCache/LockError.html +2 -2
  24. data/site/doc/classes/LocalMemCache/LockTimedOut.html +2 -2
  25. data/site/doc/classes/LocalMemCache/MemoryPoolClosed.html +2 -2
  26. data/site/doc/classes/LocalMemCache/MemoryPoolFull.html +2 -2
  27. data/site/doc/classes/LocalMemCache/OutOfMemoryError.html +2 -2
  28. data/site/doc/classes/LocalMemCache/RecoveryFailed.html +2 -2
  29. data/site/doc/classes/LocalMemCache/ShmError.html +2 -2
  30. data/site/doc/classes/LocalMemCache/ShmLockFailed.html +2 -2
  31. data/site/doc/classes/LocalMemCache/ShmUnlockFailed.html +2 -2
  32. data/site/doc/created.rid +1 -1
  33. data/site/doc/fr_class_index.html +2 -0
  34. data/site/doc/fr_file_index.html +3 -2
  35. data/site/doc/fr_method_index.html +17 -11
  36. data/site/doc/index.html +1 -1
  37. data/site/index.html +33 -17
  38. data/src/lmc_common.c +2 -1
  39. data/src/lmc_common.h +1 -1
  40. data/src/lmc_hashtable.c +62 -2
  41. data/src/lmc_hashtable.h +4 -1
  42. data/src/lmc_shm.c +1 -3
  43. data/src/lmc_shm.h +1 -3
  44. data/src/lmc_valloc.c +5 -0
  45. data/src/lmc_valloc.h +1 -0
  46. data/src/localmemcache.c +43 -8
  47. data/src/localmemcache.h +24 -6
  48. data/src/ruby-binding/localmemcache.rb +14 -29
  49. data/src/ruby-binding/rblocalmemcache.c +127 -16
  50. data/src/tests/allocfailure.rb +1 -1
  51. data/src/tests/bench.rb +1 -1
  52. data/src/tests/bench_keys.rb +1 -1
  53. data/src/tests/crash.rb +1 -1
  54. data/src/tests/lmc.rb +65 -9
  55. data/src/tests/lmctestapi.c +1 -1
  56. data/src/tests/parallelwrite.rb +1 -1
  57. data/src/tests/ttkeys +10 -0
  58. data/src/tests/ttkeys.rb +35 -0
  59. data/src/tests/ttlmc.rb +24 -6
  60. data/src/tests/ttrandom_pair +10 -0
  61. data/src/tests/ttrandom_pair.rb +23 -0
  62. metadata +8 -5
  63. data/site/doc/files/__/src/ruby-binding/extconf_rb.html +0 -108
  64. data/site/doc/files/__/src/ruby-binding/localmemcache_rb.html +0 -108
  65. data/site/doc/files/__/src/ruby-binding/rblocalmemcache_c.html +0 -101
@@ -69,7 +69,7 @@
69
69
  *
70
70
  * == Clearing memory pools
71
71
  *
72
- * Removing memory pools can be done with LocalMemCache.clear(options).
72
+ * Removing memory pools can be done with LocalMemCache.drop(options).
73
73
  *
74
74
  * == Environment
75
75
  *
@@ -136,6 +136,11 @@ int local_memcache_set(local_memcache_t *lmc, const char *key, size_t n_key,
136
136
  */
137
137
  int local_memcache_delete(local_memcache_t *lmc, char *key, size_t n_key);
138
138
 
139
+ /*
140
+ * Clears content of hashtable.
141
+ */
142
+ int local_memcache_clear(local_memcache_t *lmc);
143
+
139
144
  /*
140
145
  * Releases memory pool handle.
141
146
  */
@@ -164,14 +169,23 @@ int local_memcache_free(local_memcache_t *lmc, lmc_error_t *e);
164
169
  * triggering the automatic recovery.)
165
170
  *
166
171
  */
167
- int local_memcache_iterate(local_memcache_t *lmc, void *ctx,
172
+ int local_memcache_iterate(local_memcache_t *lmc, void *ctx, size_t *ofs,
168
173
  LMC_ITERATOR_P(iter));
169
174
 
170
175
  /*
171
- * Deletes a memory pool. If repair is 1, locked semaphores are
176
+ * Retrieves random pair from hashtable.
177
+ *
178
+ * It will return a newly allocated strings for r_key and r_value which you
179
+ * will need to free() after use.
180
+ */
181
+ int local_memcache_random_pair_new(local_memcache_t *lmc,
182
+ char **r_key, size_t *n_key, char **r_value, size_t *n_value);
183
+
184
+ /*
185
+ * Deletes a memory pool. If force is 1, locked semaphores are
172
186
  * removed as well.
173
187
  *
174
- * WARNING: Do only call this method with the repair option if you are sure
188
+ * WARNING: Do only call this method with the force option if you are sure
175
189
  * that you really want to remove this memory pool and no more processes are
176
190
  * still using it.
177
191
  *
@@ -183,8 +197,8 @@ int local_memcache_iterate(local_memcache_t *lmc, void *ctx,
183
197
  * The memory pool must be specified by either setting the filename or
184
198
  * namespace parameter.
185
199
  */
186
- int local_memcache_clear_namespace(const char *namespace, const char *filename,
187
- int repair, lmc_error_t *e);
200
+ int local_memcache_drop_namespace(const char *namespace, const char *filename,
201
+ int force, lmc_error_t *e);
188
202
  /*
189
203
  * Tries to repair a corrupt namespace. Usually one doesn't call this method
190
204
  * directly, it's invoked automatically when operations time out.
@@ -199,6 +213,10 @@ int local_memcache_check_namespace(const char *namespace, const char *filename,
199
213
  const char *__local_memcache_get(local_memcache_t *lmc,
200
214
  const char *key, size_t n_key, size_t *n_value);
201
215
 
216
+ /* internal, do not use */
217
+ int __local_memcache_random_pair(local_memcache_t *lmc,
218
+ char **r_key, size_t *n_key, char **r_value, size_t *n_value);
219
+
202
220
  /* internal, do not use */
203
221
  int lmc_unlock_shm_region(const char *who, local_memcache_t *lmc);
204
222
  #endif
@@ -14,6 +14,7 @@ class LocalMemCache
14
14
  class ShmLockFailed < LocalMemCacheError; end
15
15
  class ShmUnlockFailed < LocalMemCacheError; end
16
16
  class MemoryPoolClosed < LocalMemCacheError; end
17
+ class DBVersionNotSupported < LocalMemCacheError; end
17
18
 
18
19
  # Creates a new handle for accessing a shared memory region.
19
20
  #
@@ -41,35 +42,19 @@ class LocalMemCache
41
42
  _new(o);
42
43
  end
43
44
 
44
- # NOTE: This method is deprecated, use LocalMemCache.clear(*args) instead.
45
- #
46
- # Deletes a memory pool. If the repair flag is set, locked semaphores are
47
- # removed as well.
48
- #
49
- # If you delete a pool and other processes still have handles open on it, the
50
- # status of these handles becomes undefined. There's no way for a process to
51
- # know when a handle is not valid anymore, so only delete a memory pool if
52
- # you are sure that all handles are closed.
53
- #
54
- # WARNING: Do only call this method with the repair=true flag if you are sure
55
- # that you really want to remove this memory pool and no more processes are
56
- # still using it.
57
- def self.clear_namespace(namespace, repair = false)
58
- clear :namespace => namespace.to_s, :repair => repair
45
+ # <code>SharedObjectStorage</code> inherits from class LocalMemCache but
46
+ # stores Ruby objects as values instead of just strings (It still uses
47
+ # strings for the keys, though).
48
+ class SharedObjectStorage < LocalMemCache
49
+ def []=(key,val) super(key, Marshal.dump(val)) end
50
+ def [](key) v = super(key); v.nil? ? nil : Marshal.load(v) end
51
+ def each_pair(&block)
52
+ super {|k, mv| block.call(k, Marshal.load(mv)) }
53
+ end
54
+ def random_pair
55
+ rp = super
56
+ rp.nil? ? nil : [rp.first, Marshal.load(rp.last)]
57
+ end
59
58
  end
60
59
 
61
- # NOTE: This method is deprecated, use LocalMemCache.check(*args) instead.
62
- #
63
- # Tries to repair a corrupt namespace. Usually one doesn't call this method
64
- # directly, it's invoked automatically when operations time out.
65
- #
66
- # valid options are
67
- # [:namespace]
68
- # [:filename]
69
- #
70
- # The memory pool must be specified by either setting the :filename or
71
- # :namespace option. The default for :repair is false.
72
- def self.check_namespace(namespace)
73
- check :namespace => namespace.to_s
74
- end
75
60
  end
@@ -65,7 +65,7 @@ static VALUE LocalMemCache;
65
65
  static VALUE lmc_rb_sym_namespace;
66
66
  static VALUE lmc_rb_sym_filename;
67
67
  static VALUE lmc_rb_sym_size_mb;
68
- static VALUE lmc_rb_sym_repair;
68
+ static VALUE lmc_rb_sym_force;
69
69
 
70
70
  /* :nodoc: */
71
71
  void __rb_lmc_raise_exception(const char *error_type, const char *m) {
@@ -124,12 +124,12 @@ local_memcache_t *get_LocalMemCache(VALUE obj) {
124
124
  }
125
125
 
126
126
  /*
127
- * call-seq: LocalMemCache.clear(*args)
127
+ * call-seq: LocalMemCache.drop(*args)
128
128
  *
129
- * Deletes a memory pool. If the :repair option is set, locked semaphores are
129
+ * Deletes a memory pool. If the :force option is set, locked semaphores are
130
130
  * removed as well.
131
131
  *
132
- * WARNING: Do only call this method with the :repair option if you are sure
132
+ * WARNING: Do only call this method with the :force option if you are sure
133
133
  * that you really want to remove this memory pool and no more processes are
134
134
  * still using it.
135
135
  *
@@ -138,21 +138,21 @@ local_memcache_t *get_LocalMemCache(VALUE obj) {
138
138
  * know when a handle is not valid anymore, so only delete a memory pool if
139
139
  * you are sure that all handles are closed.
140
140
  *
141
- * valid options for clear are
141
+ * valid options for drop are
142
142
  * [:namespace]
143
143
  * [:filename]
144
- * [:repair]
144
+ * [:force]
145
145
  *
146
146
  * The memory pool must be specified by either setting the :filename or
147
- * :namespace option. The default for :repair is false.
147
+ * :namespace option. The default for :force is false.
148
148
  */
149
- static VALUE LocalMemCache__clear(VALUE klass, VALUE o) {
149
+ static VALUE LocalMemCache__drop(VALUE klass, VALUE o) {
150
150
  lmc_check_dict(o);
151
151
  lmc_error_t e;
152
- if (!local_memcache_clear_namespace(
152
+ if (!local_memcache_drop_namespace(
153
153
  rstring_ptr_null(rb_hash_aref(o, lmc_rb_sym_namespace)),
154
154
  rstring_ptr_null(rb_hash_aref(o, lmc_rb_sym_filename)),
155
- bool_value(rb_hash_aref(o, lmc_rb_sym_repair)), &e)) {
155
+ bool_value(rb_hash_aref(o, lmc_rb_sym_force)), &e)) {
156
156
  rb_lmc_raise_exception(&e);
157
157
  }
158
158
  return Qnil;
@@ -212,6 +212,27 @@ static VALUE LocalMemCache__get(VALUE obj, VALUE key) {
212
212
  return rr;
213
213
  }
214
214
 
215
+ /*
216
+ * call-seq:
217
+ * lmc.random_pair() -> [key, value] or nil
218
+ *
219
+ * Retrieves random pair from hashtable.
220
+ */
221
+ static VALUE LocalMemCache__random_pair(VALUE obj) {
222
+ char *k, *v;
223
+ size_t n_k, n_v;
224
+ VALUE r = Qnil;
225
+ if (__local_memcache_random_pair(get_LocalMemCache(obj), &k, &n_k, &v,
226
+ &n_v)) {
227
+ r = rb_ary_new();
228
+ rb_ary_push(r, lmc_ruby_string2(k, n_k));
229
+ rb_ary_push(r, lmc_ruby_string2(v, n_v));
230
+ }
231
+ lmc_unlock_shm_region("local_memcache_random_pair",
232
+ get_LocalMemCache(obj));
233
+ return r;
234
+ }
235
+
215
236
  /*
216
237
  * call-seq:
217
238
  * lmc.set(key, value) -> Qnil
@@ -229,6 +250,19 @@ static VALUE LocalMemCache__set(VALUE obj, VALUE key, VALUE value) {
229
250
  return Qnil;
230
251
  }
231
252
 
253
+
254
+ /*
255
+ * call-seq:
256
+ * lmc.clear -> Qnil
257
+ *
258
+ * Clears content of hashtable.
259
+ */
260
+ static VALUE LocalMemCache__clear(VALUE obj) {
261
+ local_memcache_t *lmc = get_LocalMemCache(obj);
262
+ if (!local_memcache_clear(lmc)) rb_lmc_raise_exception(&lmc->error);
263
+ return Qnil;
264
+ }
265
+
232
266
  /*
233
267
  * call-seq:
234
268
  * lmc.delete(key) -> Qnil
@@ -274,8 +308,12 @@ static VALUE __LocalMemCache__keys(VALUE d) {
274
308
  VALUE r = rb_ary_entry(d, 1);
275
309
  lmc_ruby_iter_collect_keys data;
276
310
  data.ary = r;
277
- int success = local_memcache_iterate(get_LocalMemCache(obj),
278
- (void *) &data, lmc_ruby_iter);
311
+ int success = 2;
312
+ size_t ofs = 0;
313
+ while (success == 2) {
314
+ success = local_memcache_iterate(get_LocalMemCache(obj),
315
+ (void *) &data, &ofs, lmc_ruby_iter);
316
+ }
279
317
  if (!success) { return Qnil; }
280
318
  return Qnil;
281
319
  }
@@ -299,6 +337,68 @@ static VALUE LocalMemCache__keys(VALUE obj) {
299
337
  return rb_ary_entry(d, 1);
300
338
  }
301
339
 
340
+ typedef struct {
341
+ VALUE ary;
342
+ } lmc_ruby_iter_collect_pairs_t;
343
+
344
+ /* :nodoc: */
345
+ int lmc_ruby_iter_collect_pairs(void *ctx, const char* key, const char* value) {
346
+ lmc_ruby_iter_collect_pairs_t *data = ctx;
347
+ rb_ary_push(data->ary, rb_assoc_new(lmc_ruby_string(key),
348
+ lmc_ruby_string(value)));
349
+ return 1;
350
+ }
351
+
352
+ /* :nodoc: */
353
+ static VALUE __LocalMemCache__each_pair(VALUE d) {
354
+ VALUE obj = rb_ary_entry(d, 0);
355
+ int success = 2;
356
+ size_t ofs = 0;
357
+ while (success == 2) {
358
+ VALUE r = rb_ary_new();
359
+ lmc_ruby_iter_collect_pairs_t data;
360
+ data.ary = r;
361
+ success = local_memcache_iterate(get_LocalMemCache(obj),
362
+ (void *) &data, &ofs, lmc_ruby_iter_collect_pairs);
363
+ long i;
364
+ for (i = 0; i < RARRAY(r)->len; i++) {
365
+ rb_yield(RARRAY(r)->ptr[i]);
366
+ }
367
+ }
368
+ if (!success) { return Qnil; }
369
+ return Qnil;
370
+ }
371
+
372
+ /*
373
+ * call-seq:
374
+ * lmc.each_pair {|k, v| block } -> nil
375
+ *
376
+ * Iterates over hashtable.
377
+ */
378
+ static VALUE LocalMemCache__each_pair(VALUE obj) {
379
+ VALUE d = rb_ary_new();
380
+ rb_ary_push(d, obj);
381
+ int error = 0;
382
+ rb_protect(__LocalMemCache__each_pair, d, &error);
383
+ if (error) {
384
+ lmc_unlock_shm_region("local_memcache_iterate", get_LocalMemCache(obj));
385
+ rb_exc_raise(ruby_errinfo);
386
+ }
387
+ return Qnil;
388
+ }
389
+
390
+ /*
391
+ * call-seq:
392
+ * lmc.size -> number
393
+ *
394
+ * Number of pairs in the hashtable.
395
+ */
396
+ static VALUE LocalMemCache__size(VALUE obj) {
397
+ local_memcache_t *lmc = get_LocalMemCache(obj);
398
+ ht_hash_t *ht = lmc->base + lmc->va_hash;
399
+ return rb_int2big(ht->size);
400
+ }
401
+
302
402
  /*
303
403
  * Document-class: LocalMemCache
304
404
  *
@@ -337,7 +437,7 @@ static VALUE LocalMemCache__keys(VALUE obj) {
337
437
  *
338
438
  * == Clearing memory pools
339
439
  *
340
- * Removing memory pools can be done with LocalMemCache.clear(options).
440
+ * Removing memory pools can be done with LocalMemCache.drop(options).
341
441
  *
342
442
  * == Environment
343
443
  *
@@ -345,12 +445,17 @@ static VALUE LocalMemCache__keys(VALUE obj) {
345
445
  * reside in /var/tmp/localmemcache. This can be overriden by setting the
346
446
  * LMC_NAMESPACES_ROOT_PATH variable in the environment.
347
447
  *
448
+ * == Storing Ruby Objects
449
+ *
450
+ * If you want to store Ruby objects instead of just strings, consider
451
+ * using LocalMemCache::SharedObjectStorage.
452
+ *
348
453
  */
349
454
  void Init_rblocalmemcache() {
350
455
  LocalMemCache = rb_define_class("LocalMemCache", rb_cObject);
351
456
  rb_define_singleton_method(LocalMemCache, "_new", LocalMemCache__new2, 1);
352
- rb_define_singleton_method(LocalMemCache, "clear",
353
- LocalMemCache__clear, 1);
457
+ rb_define_singleton_method(LocalMemCache, "drop",
458
+ LocalMemCache__drop, 1);
354
459
  rb_define_singleton_method(LocalMemCache, "check",
355
460
  LocalMemCache__check, 1);
356
461
  rb_define_singleton_method(LocalMemCache, "disable_test_crash",
@@ -361,12 +466,18 @@ void Init_rblocalmemcache() {
361
466
  rb_define_method(LocalMemCache, "[]", LocalMemCache__get, 1);
362
467
  rb_define_method(LocalMemCache, "delete", LocalMemCache__delete, 1);
363
468
  rb_define_method(LocalMemCache, "set", LocalMemCache__set, 2);
469
+ rb_define_method(LocalMemCache, "clear", LocalMemCache__clear, 0);
364
470
  rb_define_method(LocalMemCache, "[]=", LocalMemCache__set, 2);
365
471
  rb_define_method(LocalMemCache, "keys", LocalMemCache__keys, 0);
472
+ rb_define_method(LocalMemCache, "each_pair", LocalMemCache__each_pair, 0);
473
+ rb_define_method(LocalMemCache, "random_pair", LocalMemCache__random_pair,
474
+ 0);
366
475
  rb_define_method(LocalMemCache, "close", LocalMemCache__close, 0);
476
+ rb_define_method(LocalMemCache, "size", LocalMemCache__size, 0);
367
477
 
368
478
  lmc_rb_sym_namespace = ID2SYM(rb_intern("namespace"));
369
479
  lmc_rb_sym_filename = ID2SYM(rb_intern("filename"));
370
480
  lmc_rb_sym_size_mb = ID2SYM(rb_intern("size_mb"));
371
- lmc_rb_sym_repair = ID2SYM(rb_intern("repair"));
481
+ lmc_rb_sym_force = ID2SYM(rb_intern("force"));
482
+ rb_require("localmemcache.rb");
372
483
  }
@@ -3,7 +3,7 @@ $DIR=File.dirname(__FILE__)
3
3
 
4
4
  require 'localmemcache'
5
5
 
6
- LocalMemCache.clear_namespace("alloc-failure-test", true);
6
+ LocalMemCache.drop :namespace => "alloc-failure-test", :force => true
7
7
 
8
8
 
9
9
  LocalMemCache.enable_test_crash
@@ -6,7 +6,7 @@ require 'localmemcache'
6
6
 
7
7
  Bacon.summary_on_exit
8
8
 
9
- LocalMemCache.clear_namespace("speed-comparison");
9
+ LocalMemCache.drop :namespace => "speed-comparison", :force => true
10
10
  $lm2 = LocalMemCache.new :namespace=>"speed-comparison"
11
11
 
12
12
  def compare_speed(n)
@@ -6,7 +6,7 @@ require 'localmemcache'
6
6
 
7
7
  Bacon.summary_on_exit
8
8
 
9
- LocalMemCache.clear_namespace("speed-comparison");
9
+ LocalMemCache.drop :namespace => "speed-comparison", :force => true
10
10
  $lm2 = LocalMemCache.new :namespace=>"speed-comparison"
11
11
 
12
12
 
@@ -3,7 +3,7 @@ $DIR=File.dirname(__FILE__)
3
3
 
4
4
  require 'localmemcache'
5
5
 
6
- LocalMemCache.clear_namespace("crash-t", true);
6
+ LocalMemCache.drop :namespace => "crash-t", :force => true
7
7
  #exit
8
8
  #puts "c"
9
9
  #LocalMemCache.check_namespace("crash-t");
@@ -6,10 +6,10 @@ require 'localmemcache'
6
6
 
7
7
  Bacon.summary_on_exit
8
8
 
9
- LocalMemCache.clear_namespace("test", true)
10
- $lm = LocalMemCache.new :namespace=>"test"
9
+ LocalMemCache.drop :namespace => "test", :force => true
10
+ $lm = LocalMemCache.new :namespace=>"test", :size_mb => 20
11
11
 
12
- LocalMemCache.clear_namespace("test-small", true)
12
+ LocalMemCache.drop :namespace => "test-small", :force => true
13
13
  $lms = LocalMemCache.new :namespace=>"test-small", :size_mb => 0.20;
14
14
 
15
15
  describe 'LocalMemCache' do
@@ -37,11 +37,22 @@ describe 'LocalMemCache' do
37
37
  $lm.keys().size.should.equal 2
38
38
  end
39
39
 
40
+ it 'should support each_pair' do
41
+ $lm.each_pair {|k, v| }
42
+ end
43
+
40
44
  it 'should support \0 in values and keys' do
41
45
  $lm["null"] = "foo\0goo"
42
46
  $lm["null"].should.equal "foo\0goo"
43
47
  end
44
48
 
49
+ it 'should support random_pair' do
50
+ $lm.random_pair.size.should.equal 2
51
+ LocalMemCache.drop :namespace => :empty, :force => true
52
+ ll = LocalMemCache.new :namespace => :empty
53
+ ll.random_pair.should.be.nil
54
+ end
55
+
45
56
  it 'should throw an exception when accessing a closed pool' do
46
57
  $lm.close
47
58
  should.raise(LocalMemCache::MemoryPoolClosed) { $lm.keys }
@@ -52,23 +63,68 @@ describe 'LocalMemCache' do
52
63
  should.raise(LocalMemCache::MemoryPoolFull) { $lms["two"] = "b" * 8000000; }
53
64
  end
54
65
 
66
+
67
+ it 'should support clearing of the hashtable' do
68
+ ($lms.size > 0).should.be.true
69
+ $lms.clear
70
+ $lms.size.should.equal 0
71
+ end
72
+
73
+ it 'should support size' do
74
+ LocalMemCache.drop :namespace =>"size-test", :force=>true
75
+ ll = LocalMemCache.new :namespace => "size-test", :size_mb => 0.2
76
+ ll.size.should.equal 0
77
+ ll[:one] = 1
78
+ ll.size.should.equal 1
79
+ ll.delete(:one)
80
+ ll.size.should.equal 0
81
+ ll[:foo] = 1
82
+ ll.size.should.equal 1
83
+ ll[:goo] = 2
84
+ ll.size.should.equal 2
85
+ ll.clear
86
+ ll.size.should.equal 0
87
+ end
88
+
89
+
55
90
  it 'should support checking of namespaces' do
56
- LocalMemCache.check_namespace("test")
91
+ LocalMemCache.check :namespace => "test"
57
92
  end
58
93
 
59
- it 'should support clearing of namespaces' do
60
- LocalMemCache.clear_namespace("test")
94
+
95
+ it 'should support dropping of namespaces' do
96
+ LocalMemCache.drop :namespace => "test"
61
97
  end
62
98
 
63
99
  it 'should support filename parameters' do
64
- lm = LocalMemCache.new :filename => ".tmp.a.lmc"
100
+ LocalMemCache.drop :filename => ".tmp.a.lmc", :force => true
101
+ lm = LocalMemCache.new :filename => ".tmp.a.lmc", :size_mb => 0.20
65
102
  lm[:boo] = 1
66
- lm.keys.size.should.equal 1
103
+ lm.size.should.equal 1
67
104
  File.exists?(".tmp.a.lmc").should.be.true
68
105
  LocalMemCache.check :filename => ".tmp.a.lmc"
69
- LocalMemCache.clear :filename => ".tmp.a.lmc"
106
+ LocalMemCache.drop :filename => ".tmp.a.lmc"
70
107
  end
71
108
 
109
+ end
72
110
 
111
+ LocalMemCache.drop :namespace => "test-shared-os", :force => true
112
+ $lmsh = LocalMemCache::SharedObjectStorage.new :namespace=>"test-shared-os",
113
+ :size_mb => 20
114
+
115
+ describe 'LocalMemCache::SharedObjectStorage' do
116
+ it 'should allow to set and query for ruby objects' do
117
+ $lmsh["non-existant"].should.be.nil
118
+ $lmsh["array"] = [:foo, :boo]
119
+ $lmsh["array"].should.be.kind_of? Array
120
+ end
121
+
122
+ it 'support iteration' do
123
+ $lmsh.each_pair {|k, v| v.should.be.kind_of? Array }
124
+ end
125
+
126
+ it 'support random_pair' do
127
+ $lmsh.random_pair.last.should.be.kind_of? Array
128
+ end
73
129
  end
74
130