Permalink
Browse files

o キャッシュの初期化がされていないと動作しなかったのを修正

o xt追加
  • Loading branch information...
1 parent aabff7f commit 367f945e91e2515b49cf21a643e962b07d8562da @dragon3 committed May 20, 2009
View
@@ -24,3 +24,9 @@ META.yml
README
t/00_compile.t
t/01_new.t
+t/02_keys.t
+t/02_make_url.t
+t/03_keys.t
+xt/97_podspell.t
+xt/98_perlcritic.t
+xt/99_pod.t
View
@@ -8,14 +8,22 @@
use Cache::Ehcache;
my $cache = Cache::Ehcache->new( namespace => 'cache_ehcache' );
+
+print "Set cacahe\n";
+
$cache->set( 'foo', 'bar' );
+
+print "Get cacahe\n";
print $cache->get('foo') . "\n";
+print "Delete cacahe\n";
$cache->delete('foo');
print $cache->get('foo') . "\n";
+print "Delete cacahe\n";
$cache->delete('baz');
+print "Clear cacahe\n";
$cache->clear;
exit;
View
@@ -53,6 +53,12 @@ sub BUILDARGS {
return {%args};
}
+sub BUILD {
+ my $self = shift;
+ my $req = HTTP::Request->new( 'PUT', $self->_make_url() );
+ my $res = $self->ua->request($req);
+}
+
__PACKAGE__->meta->make_immutable;
no Moose;
@@ -69,7 +75,7 @@ sub set {
HTTP::Request->new( 'PUT', $self->_make_url($key), \@header, $value );
my $res = $self->ua->request($req);
unless ( $res->is_success ) {
- warn $res->status_line;
+ warn $res->status_line . "\n";
}
}
@@ -81,7 +87,7 @@ sub get {
return $res->decoded_content;
}
elsif ( $res->code != HTTP_NOT_FOUND ) {
- warn $res->status_line;
+ warn $res->status_line . "\n";
}
}
@@ -91,7 +97,7 @@ sub delete {
my $req = HTTP::Request->new( 'DELETE', $self->_make_url($key) );
my $res = $self->ua->request($req);
if ( !$res->is_success && $res->code != HTTP_NOT_FOUND ) {
- warn $res->status_line;
+ warn $res->status_line . "\n";
}
}
@@ -100,7 +106,7 @@ sub clear {
my $req = HTTP::Request->new( 'DELETE', $self->_make_url('*') );
my $res = $self->ua->request($req);
unless ( $res->is_success ) {
- warn $res->status_line;
+ warn $res->status_line . "\n";
}
}
View
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok('Cache::Ehcache'); }
+
+my $cache = Cache::Ehcache->new( namespace => 'foo', );
+is( $cache->_make_url, 'http://localhost:8080/ehcache/rest/foo' );
+is( $cache->_make_url("bar"), 'http://localhost:8080/ehcache/rest/foo/bar' );
View
@@ -0,0 +1,46 @@
+use strict;
+use warnings;
+use Test::More;
+use IO::Socket::INET;
+
+use Cache::Ehcache;
+
+my $skip = 1;
+my $addr = "127.0.0.1:8080";
+my $sock =
+ IO::Socket::INET->new( PeerAddr => $addr, Proto => 'tcp', Timeout => 3 );
+if ($sock) {
+ $sock->send("GET /ehcache/rest/foo\n\n");
+ my $buf;
+ $sock->recv( $buf, 1024 );
+ $skip = 0 if ($buf);
+}
+if ($skip) {
+ plan skip_all => "No Ehcache Server running at $addr\n";
+ exit 0;
+}
+else {
+ plan tests => 9;
+}
+
+my $cache = Cache::Ehcache->new(
+ server => 'http://127.0.0.1:8080/ehcache/rest/',
+ namespace => "Cache_Ehcache_Test",
+);
+
+isa_ok( $cache, 'Cache::Ehcache' );
+
+ok( $cache->set( "key1", "val1" ), "set key1 as val1" );
+ok( $cache->set( "key2", "val2" ), "set key2 as val2" );
+
+is( $cache->get("key1"), "val1", "get key1 is val1" );
+is( $cache->get("key2"), "val2", "get key2 is val2" );
+
+ok( $cache->set( "key2", "val-replace" ), "set key2 as val-replace" );
+is( $cache->get("key2"), "val-replace", "get key2 is val-replace" );
+
+$cache->delete("key1");
+ok( !$cache->get("key1"), "get key1 properly failed" );
+
+$cache->clear;
+ok( !$cache->get("key2"), "get key2 properly failed" );
@@ -8,3 +8,7 @@ Ryuzo
Yamamoto
YAMAMOTO
Ehcache
+API
+RESTful
+java
+memcached
File renamed without changes.
File renamed without changes.

0 comments on commit 367f945

Please sign in to comment.