From ee7e789e2b6b3e1cde2acf3e4d7f303ad563e6eb Mon Sep 17 00:00:00 2001 From: bin.shen <bluelazysb@hotmail.com> Date: Wed, 30 Nov 2016 21:29:53 +0800 Subject: [PATCH] updates --- .idea/vcs.xml | 6 + moral_socket.iml | 16 ++++ .idea/modules.xml | 8 ++ priv/bson-erlang | 2 priv/mongodb-erlang | 2 src/test.erl | 126 ++++++++++++++++++++++++++++++- .idea/misc.xml | 32 ++++++++ 7 files changed, 186 insertions(+), 6 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8561c22 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="true"> + <output url="file://$PROJECT_DIR$/out" /> + </component> + <component name="SbtLocalSettings"> + <option name="modificationStamps"> + <map> + <entry key="$USER_HOME$/IdeaProjects/play2" value="1478179325000" /> + </map> + </option> + <option name="externalProjectsViewState"> + <projects_view /> + </option> + </component> + <component name="masterDetails"> + <states> + <state key="ProjectJDKs.UI"> + <settings> + <last-edited>1.8</last-edited> + <splitter-proportions> + <option name="proportions"> + <list> + <option value="0.2" /> + </list> + </option> + </splitter-proportions> + </settings> + </state> + </states> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ddcfd44 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/moral_socket.iml" filepath="$PROJECT_DIR$/moral_socket.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/moral_socket.iml b/moral_socket.iml new file mode 100644 index 0000000..54d5faa --- /dev/null +++ b/moral_socket.iml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="ERLANG_MODULE" version="4"> + <component name="FacetManager"> + <facet type="erlang" name="Erlang"> + <configuration /> + </facet> + </component> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="jdk" jdkName="Erlang 19" jdkType="Erlang SDK" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/priv/bson-erlang b/priv/bson-erlang new file mode 160000 index 0000000..42b19de --- /dev/null +++ b/priv/bson-erlang @@ -1 +1 @@ -Subproject commit 0000000000000000000000000000000000000000 +Subproject commit 42b19ded9f08910c8bcd0ee1424e9231bc6eae65 diff --git a/priv/mongodb-erlang b/priv/mongodb-erlang new file mode 160000 index 0000000..bb36cb3 --- /dev/null +++ b/priv/mongodb-erlang @@ -1 +1 @@ -Subproject commit 0000000000000000000000000000000000000000 +Subproject commit bb36cb3d490772fdf8d6cb3024de0e3afe4e25fb diff --git a/src/test.erl b/src/test.erl index 2d46237..b837d57 100644 --- a/src/test.erl +++ b/src/test.erl @@ -12,8 +12,126 @@ %% API -export([init/0]). +%%-include_lib("eunit/include/eunit.hrl"). +%%-include("../priv/mongodb-erlang/include/mongo_protocol.hrl"). + +%-include("/Users/bin.shen/git/rabbitmq-erlang-client/include/amqp_client.hrl"). + + init() -> - A = <<1,2>>, - B = <<3,4,5>>, - C = <<A/binary, B/binary>>, - io:format("~p~n", [C]). \ No newline at end of file +%% A = <<1,2>>, +%% B = <<3,4,5>>, +%% C = <<A/binary, B/binary>>, +%% io:format("~p~n", [C]){port, 27017}, + + %% application:ensure_all_started(mongodb), + + + application:start (bson), + application:start (crypto), + application:start (poolboy), + application:start (mongodb), + + +%% Database = <<"test1">>, +%% {ok, Connection} = mc_worker_api:connect ([{database, Database}]), +%% io:format("Connection ~p~n", [Connection]), +%% +%% Collection = <<"test2">>, +%% mc_worker_api:insert(Connection, Collection, [ +%% {<<"name">>, <<"Yankees">>, <<"home">>, {<<"city">>, <<"New York">>, <<"state">>, <<"NY">>}, <<"league">>, <<"American">>}, +%% {<<"name">>, <<"Mets">>, <<"home">>, {<<"city">>, <<"New York">>, <<"state">>, <<"NY">>}, <<"league">>, <<"National">>}, +%% {<<"name">>, <<"Phillies">>, <<"home">>, {<<"city">>, <<"Philadelphia">>, <<"state">>, <<"PA">>}, <<"league">>, <<"National">>}, +%% {<<"name">>, <<"Red Sox">>, <<"home">>, {<<"city">>, <<"Boston">>, <<"state">>, <<"MA">>}, <<"league">>, <<"American">>} +%% ]), + +%% Database = <<"test1">>, +%% case mc_worker_api:connect([ +%% {database, Database}, +%% {host, "127.0.0.1"}, +%% {port, 27017} +%% ]) of +%% {ok, Connection} -> +%% io:format("Connection ~p~n", [Connection]), +%% +%% Cursor = mc_worker_api:find(Connection, <<"test2">>, {}), +%% io:format("~p cursor: ~p~n", [self(), Cursor]), +%% mc_cursor:close(Cursor); +%% +%% {error, Reason} -> +%% io:format("unable to connect to ~p: ~p~n", [Database, Reason]) +%% end, + + {ok, Connection} = mc_worker_api:connect([ + {database, <<"moral_db">>}, + {login, <<"moral_user">>}, + {password, <<"m2o0r1a6l_passw0rd">>}, + {host, "121.40.92.176"}, + {port, 27017} + ]), + + io:format("Connection is XXX : ~p~n", [Connection]), + io:format("*****************###"), + + mc_worker_api:insert(Connection, <<"alerts">>, [ + {<<"mac">>, <<"accf23b87fbf">>, <<"x1">>, <<"1">>, <<"x2">>, <<"2">>} + ]), + +%% Cursor = mc_worker_api:find_one(Connection, <<"test2">>, {}), + + +%% Cursor = mc_worker_api:find(Connection, <<"alerts">>, {}), +%% Result = mc_cursor:rest(Cursor), +%% io:format("~p~n", [Result]), +%% mc_cursor:close(Cursor), +%% mc_worker_api:disconnect(Connection), + +%%process({}) -> +%% ok; +%% +%%process(Cursor) -> +%% io:format("----Cursor:~p~n", [Cursor]), +%% Record = mc_worker_api:(Cursor), +%% io:format("Record:~p~n", [Record]), +%% case Record of +%% {} -> +%% no_more; +%% _ -> +%% process(Cursor) +%% end, + +%% {ok, Connection} = amqp_connection:start(#amqp_params_network{}), +%% %% Open a channel on the connection +%% {ok, Channel} = amqp_connection:open_channel(Connection), + +%% %% Declare a queue +%% #'queue.declare_ok'{queue = Q} = amqp_channel:call(Channel, #'queue.declare'{}), +%% +%% %% Publish a message +%% Payload = <<"foobar">>, +%% Publish = #'basic.publish'{exchange = <<>>, routing_key = Q}, +%% amqp_channel:cast(Channel, Publish, #amqp_msg{payload = Payload}), +%% +%% %% Get the message back from the queue +%% Get = #'basic.get'{queue = Q}, +%% {#'basic.get_ok'{delivery_tag = Tag}, Content} +%% = amqp_channel:call(Channel, Get), +%% +%% %% Do something with the message payload +%% %% (some work here) +%% +%% %% Ack the message +%% amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}), +%% +%% %% Close the channel +%% amqp_channel:close(Channel), +%% %% Close the connection +%% amqp_connection:close(Connection), + +%% application:start(emongo), +%% emongo:add_pool(pool1, "192.168.1.102", 27017, "test1", 1), +%% emongo:insert(pool1, "test2", {name:2334}), + + io:format("*****************###"), + + ok. -- Gitblit v1.8.0