diff options
-rw-r--r-- | src/chttpd/test/eunit/chttpd_db_test.erl | 24 | ||||
-rw-r--r-- | src/mem3/src/mem3_util.erl | 16 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/chttpd/test/eunit/chttpd_db_test.erl b/src/chttpd/test/eunit/chttpd_db_test.erl index 17250199a..c819bdf6e 100644 --- a/src/chttpd/test/eunit/chttpd_db_test.erl +++ b/src/chttpd/test/eunit/chttpd_db_test.erl @@ -73,6 +73,7 @@ all_test_() -> fun should_not_return_update_seq_when_unset_on_all_docs/1, fun should_return_correct_id_on_doc_copy/1, fun should_return_400_for_bad_engine/1, + fun should_not_change_db_proper_after_rewriting_shardmap/1, fun should_succeed_on_all_docs_with_queries_keys/1, fun should_succeed_on_all_docs_with_queries_limit_skip/1, fun should_succeed_on_all_docs_with_multiple_queries/1, @@ -297,6 +298,29 @@ should_return_400_for_bad_engine(_) -> end)}. +should_not_change_db_proper_after_rewriting_shardmap(_) -> + {timeout, ?TIMEOUT, ?_test(begin + TmpDb = ?tempdb(), + Addr = config:get("chttpd", "bind_address", "127.0.0.1"), + Port = mochiweb_socket_server:get(chttpd, port), + AdmPort = mochiweb_socket_server:get(couch_httpd, port), + + BaseUrl = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(TmpDb)]), + Url = BaseUrl ++ "?partitioned=true&q=1", + {ok, 201, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"), + + ShardDbName = ?l2b(config:get("mem3", "shards_db", "_dbs")), + {ok, ShardDb} = mem3_util:ensure_exists(ShardDbName), + {ok, #doc{body = {Props}}} = couch_db:open_doc( + ShardDb, TmpDb, [ejson_body]), + Shards = mem3_util:build_shards(TmpDb, Props), + + {Prop2} = ?JSON_DECODE(?JSON_ENCODE({Props})), + Shards2 = mem3_util:build_shards(TmpDb, Prop2), + ?assertEqual(Shards2, Shards) + end)}. + + should_succeed_on_all_docs_with_queries_keys(Url) -> {timeout, ?TIMEOUT, ?_test(begin [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)], diff --git a/src/mem3/src/mem3_util.erl b/src/mem3/src/mem3_util.erl index e8cba5d7b..3fc9b4f8e 100644 --- a/src/mem3/src/mem3_util.erl +++ b/src/mem3/src/mem3_util.erl @@ -221,11 +221,25 @@ get_engine_opt(DocProps) -> get_props_opt(DocProps) -> case couch_util:get_value(<<"props">>, DocProps) of {Props} when is_list(Props) -> - [{props, Props}]; + [{props, db_props_from_json(Props)}]; _ -> [] end. +db_props_from_json([]) -> + []; + +db_props_from_json([{<<"partitioned">>, Value} | Rest]) -> + [{partitioned, Value} | db_props_from_json(Rest)]; + +db_props_from_json([{<<"hash">>, [MBin, FBin, A]} | Rest]) -> + M = binary_to_existing_atom(MBin, utf8), + F = binary_to_existing_atom(FBin, utf8), + [{hash, [M, F, A]} | db_props_from_json(Rest)]; + +db_props_from_json([{K, V} | Rest]) -> + [{K, V} | db_props_from_json(Rest)]. + n_val(undefined, NodeCount) -> n_val(config:get("cluster", "n", "3"), NodeCount); n_val(N, NodeCount) when is_list(N) -> |