Skip to content

Commit

Permalink
Merge pull request #5 from tanmaykm/tanmaykm
Browse files Browse the repository at this point in the history
enable memcached test and code coverage
  • Loading branch information
tanmaykm committed Jul 12, 2016
2 parents cfe39e5 + 93ed967 commit 3b2f8c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ os:
- linux
- osx
julia:
- release
- 0.4
- nightly
services:
- memcached
before_install:
- if [ "$TRAVIS_OS_NAME" = osx ]; then brew update; fi
- if [ "$TRAVIS_OS_NAME" = osx ]; then brew install memcached; fi
- if [ "$TRAVIS_OS_NAME" = osx ]; then /usr/local/opt/memcached/bin/memcached -d; fi
notifications:
email: false
# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("Memcache"); Pkg.test("Memcache")'
- julia -e 'Pkg.clone(pwd()); Pkg.build("Memcache"); Pkg.test("Memcache"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("Memcache")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder());'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Julia Memcache Client

[![Build Status](https://travis-ci.org/tanmaykm/Memcache.jl.png)](https://travis-ci.org/tanmaykm/Memcache.jl)
[![Coverage Status](https://coveralls.io/repos/github/tanmaykm/Memcache.jl/badge.svg?branch=master)](https://coveralls.io/github/tanmaykm/Memcache.jl?branch=master)

A pure Julia client for memcached servers. All [memcached commands](https://github.com/memcached/memcached/wiki/Commands) as of memcached version 1.4.17 are implemented.

Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ using Memcache
using Base.Test

@test isa(Memcache, Module)

include("test.jl")
43 changes: 22 additions & 21 deletions test/test.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using Memcache
using Compat
using Base.Test


function test_begin()
mc = MemcacheClient()
mc.debug = true

st = stats(mc)
@assert st["version"] == version(mc)
@test st["version"] == version(mc)

flush_all(mc)

st = stats(mc, "settings")
@assert st["tcpport"] == "11211"
@test st["tcpport"] == "11211"

mc
end
Expand All @@ -21,11 +22,11 @@ function test_end(mc)
flush_all(mc)

st = stats(mc)
@assert parse(Int, st["get_hits"]) > 0
@test parse(Int, st["get_hits"]) > 0

@assert length(stats(mc, "items")) >= 0
@assert length(stats(mc, "sizes")) >= 0
@assert parse(Int, stats(mc, "slabs")["active_slabs"]) >= 0
@test length(stats(mc, "items")) >= 0
@test length(stats(mc, "sizes")) >= 0
@test parse(Int, stats(mc, "slabs")["active_slabs"]) >= 0

# commented out to avoid julia issue #5793
#close(mc)
Expand All @@ -34,54 +35,54 @@ end

function test_set_get(mc)
set(mc, "key1", "val1")
@assert get(mc, "key1") == "val1"
@test get(mc, "key1") == "val1"

set(mc, "key2", "val2")
res = get(mc, "key1", "key2")
@assert res["key1"] == "val1"
@assert res["key2"] == "val2"
@test res["key1"] == "val1"
@test res["key2"] == "val2"

delete(mc, "key1")
res = get(mc, "key1", "key2")
@assert collect(keys(res)) == ["key2"]
@test collect(keys(res)) == ["key2"]
end

function test_touch(mc)
set(mc, "touch_key1", "touch_val1", exptime=2)
set(mc, "touch_key2", "touch_val2", exptime=1000)
sleep(3)
res = get(mc, "touch_key1", "touch_key2")
@assert collect(keys(res)) == ["touch_key2"]
@test collect(keys(res)) == ["touch_key2"]

touch(mc, "touch_key2", 2)
set(mc, "touch_key1", "touch_val1", exptime=1000)
sleep(3)
res = get(mc, "touch_key1", "touch_key2")
@assert collect(keys(res)) == ["touch_key1"]
@test collect(keys(res)) == ["touch_key1"]
end

function test_incr_decr(mc)
set(mc, "num1", 1)
incr(mc, "num1", 5)
@assert get(mc, "num1") == 6
@test get(mc, "num1") == 6

decr(mc, "num1", 2)
@assert get(mc, "num1") == 4
@test get(mc, "num1") == 4
end

function test_cas(mc)
set(mc, "cas_key", 1)
res = get(mc, "cas_key", cas=true)
val,casval = res["cas_key"]
@assert val == 1
@test val == 1

cas(mc, "cas_key", 2, casval)
res = get(mc, "cas_key", cas=true)
val,casval2 = res["cas_key"]
@assert val == 2
@assert casval != casval2
@test val == 2
@test casval != casval2

@assert false == try cas(mc, "cas_key", 3, casval); true; catch; false; end
@test false == try cas(mc, "cas_key", 3, casval); true; catch; false; end
end

type mytype
Expand All @@ -94,9 +95,9 @@ function test_julia_type(mc)
t = mytype(10, "hello", @compat(Dict(1=>"A", 2=>"B")))
set(mc, "jul", t)
t1 = get(mc, "jul")
@assert t.i == t1.i
@assert t.s == t1.s
@assert t.k == t1.k
@test t.i == t1.i
@test t.s == t1.s
@test t.k == t1.k
end

mc = test_begin()
Expand Down

0 comments on commit 3b2f8c5

Please sign in to comment.