dnet_remove_object_raw() should return error if it failed and dnet_trans_create_send_...
[elliptics.git] / bindings / python / test.py
blob7f2f3ccebaad52e78907af1ce885822160ef997c
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 import sys
5 sys.path.insert(0, "bindings/python/.libs/")
6 from libelliptics_python import *
7 import binascii
8 from pprint import pprint
10 try:
11 log = elliptics_log_file("/dev/stderr", 31)
12 cfg = elliptics_config()
13 cfg.cookie = "0123456789012345678901234567890123456789"
14 cfg.config.wait_timeout = 60
16 n = elliptics_node_python(log, cfg)
18 n.add_groups([1,2,3])
19 n.add_remote("localhost", 1025)
21 group = 1
22 try:
23 obj = "qwerty.xml"
24 addr = n.lookup_addr(obj, group)
25 print "object", obj, "should live at", addr, "in group", group
26 except Exception as e:
27 print "Failed to lookup in group", group, ":", e
29 id = elliptics_id([1, 2, 3, 4], 1, 0)
31 # write data by ID into specified group (# 2)
32 # read data from the same group (# 2)
33 try:
34 data = '1234567890qwertyuio'
35 n.write_data(id, data, 0, 0, 0)
36 print "WRITE:", data
37 n.write_metadata(id, "", [1], 0)
38 print "Write metadata"
39 except Exception as e:
40 print "Failed to write data by id:", e
42 try:
43 s = n.read_data(id, 0, 0, 0, 0)
44 print " READ:", s
45 except Exception as e:
46 print "Failed to read data by id:", e
48 id.type = -1
49 n.remove(id, 0)
50 try:
51 s = n.read_data(id, 0, 0, 0, 0)
52 print " READ:", s
53 except Exception as e:
54 print "Failed to read data by id:", e
56 # write data into all 3 groups specified in add_groups() call.
57 # read data from the first available group
58 try:
59 key = "test.txt"
60 data = '1234567890qwertyuio'
61 n.write_data(key, data, 0, 0, 0, 0)
62 print "WRITE:", key, ":", data
63 n.write_metadata(key, 0)
64 print "Write metadata"
65 except Exception as e:
66 print "Failed to write data by string:", e
68 try:
69 key = "test.txt"
70 s = n.read_data("test.txt", 0, 0, 0, 0, 0)
71 print " READ:", key, ":", s
72 except Exception as e:
73 print "Failed to read data by string:", e
75 try:
76 print n.read_latest("test.txt", 0, 0, 0, 0, 0);
77 except Exception as e:
78 print "Failed to read latest data by string:", e
80 # bulk read of keys by name
81 try:
82 files = n.bulk_read(["test1", "test2", "test3", "test4", "test5"], 1, 0)
83 for f in files:
84 print binascii.hexlify(f[:6]), ":", f[68:]
85 except Exception as e:
86 print "Failed to read bulk:", e
88 routes = n.get_routes()
89 for route in routes:
90 print route[0].group_id, route[0].id, route[1]
92 print "Requesting stat_log"
93 pprint(n.stat_log())
95 except:
96 print "Unexpected error:", sys.exc_info()