forked from sanikoyes/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cloudwu#221 from cloudwu/dev
release 0.9.3
- Loading branch information
Showing
10 changed files
with
151 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
local skynet = require "skynet" | ||
local mongo = require "mongo" | ||
local bson = require "bson" | ||
|
||
local host, db_name = ... | ||
|
||
function test_insert_without_index() | ||
local db = mongo.client({host = host}) | ||
|
||
db[db_name].testdb:dropIndex("*") | ||
db[db_name].testdb:drop() | ||
|
||
local ret = db[db_name].testdb:safe_insert({test_key = 1}); | ||
assert(ret and ret.n == 1) | ||
|
||
local ret = db[db_name].testdb:safe_insert({test_key = 1}); | ||
assert(ret and ret.n == 1) | ||
end | ||
|
||
function test_insert_with_index() | ||
local db = mongo.client({host = host}) | ||
|
||
db[db_name].testdb:dropIndex("*") | ||
db[db_name].testdb:drop() | ||
|
||
db[db_name].testdb:ensureIndex({test_key = 1}, {unique = true, name = "test_key_index"}) | ||
|
||
local ret = db[db_name].testdb:safe_insert({test_key = 1}) | ||
assert(ret and ret.n == 1) | ||
|
||
local ret = db[db_name].testdb:safe_insert({test_key = 1}) | ||
assert(ret and ret.n == 0) | ||
end | ||
|
||
function test_find_and_remove() | ||
local db = mongo.client({host = host}) | ||
|
||
db[db_name].testdb:dropIndex("*") | ||
db[db_name].testdb:drop() | ||
|
||
db[db_name].testdb:ensureIndex({test_key = 1}, {unique = true, name = "test_key_index"}) | ||
|
||
local ret = db[db_name].testdb:safe_insert({test_key = 1}) | ||
assert(ret and ret.n == 1) | ||
|
||
local ret = db[db_name].testdb:findOne({test_key = 1}) | ||
assert(ret and ret.test_key == 1) | ||
|
||
db[db_name].testdb:delete({test_key = 1}) | ||
|
||
local ret = db[db_name].testdb:findOne({test_key = 1}) | ||
assert(ret == nil) | ||
end | ||
|
||
|
||
function test_expire_index() | ||
local db = mongo.client({host = host}) | ||
|
||
db[db_name].testdb:dropIndex("*") | ||
db[db_name].testdb:drop() | ||
|
||
db[db_name].testdb:ensureIndex({test_key = 1}, {unique = true, name = "test_key_index", expireAfterSeconds = 1, }) | ||
db[db_name].testdb:ensureIndex({test_date = 1}, {expireAfterSeconds = 1, }) | ||
|
||
local ret = db[db_name].testdb:safe_insert({test_key = 1, test_date = bson.date(os.time())}) | ||
assert(ret and ret.n == 1) | ||
|
||
local ret = db[db_name].testdb:findOne({test_key = 1}) | ||
assert(ret and ret.test_key == 1) | ||
|
||
for i = 1, 1000 do | ||
skynet.sleep(11); | ||
|
||
local ret = db[db_name].testdb:findOne({test_key = 1}) | ||
if ret == nil then | ||
return | ||
end | ||
end | ||
|
||
assert(false, "test expire index failed"); | ||
end | ||
|
||
skynet.start(function() | ||
test_insert_without_index() | ||
test_insert_with_index() | ||
test_find_and_remove() | ||
test_expire_index() | ||
|
||
print("mongodb test finish."); | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters