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

---
 src/test.erl |  126 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 122 insertions(+), 4 deletions(-)

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