diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2015-03-21 03:38:29 +0000 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2015-03-21 03:38:29 +0000 |
commit | c77d4e5c69ac54ffddf5bd60c18bcb0504389311 (patch) | |
tree | bb40b73db6ed428d6ab44ffee91ca0ed6f16b592 /src/datastore/test_plugin_datastore.c | |
parent | ce6f1156a58aafed6563585b3be560ec0b4eabe7 (diff) | |
download | gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.tar.gz gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.zip |
Convert datastore plugin API to asynchronous
Diffstat (limited to 'src/datastore/test_plugin_datastore.c')
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 107 |
1 files changed, 64 insertions, 43 deletions
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index ee582a97e..64e88b819 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c | |||
@@ -84,6 +84,35 @@ disk_utilization_change_cb (void *cls, int delta) | |||
84 | 84 | ||
85 | 85 | ||
86 | static void | 86 | static void |
87 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
88 | |||
89 | |||
90 | static void | ||
91 | put_continuation (void *cls, const struct GNUNET_HashCode *key, | ||
92 | uint32_t size, int status, char *msg) | ||
93 | { | ||
94 | struct CpsRunContext *crc = cls; | ||
95 | static unsigned long long os; | ||
96 | unsigned long long cs; | ||
97 | |||
98 | if (GNUNET_OK != status) | ||
99 | { | ||
100 | FPRINTF (stderr, "ERROR: `%s'\n", msg); | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | crc->api->estimate_size (crc->api->cls, &cs); | ||
105 | GNUNET_assert (os <= cs); | ||
106 | os = cs; | ||
107 | stored_bytes += size; | ||
108 | stored_ops++; | ||
109 | stored_entries++; | ||
110 | } | ||
111 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
112 | } | ||
113 | |||
114 | |||
115 | static void | ||
87 | gen_key (int i, struct GNUNET_HashCode * key) | 116 | gen_key (int i, struct GNUNET_HashCode * key) |
88 | { | 117 | { |
89 | memset (key, 0, sizeof (struct GNUNET_HashCode)); | 118 | memset (key, 0, sizeof (struct GNUNET_HashCode)); |
@@ -93,14 +122,21 @@ gen_key (int i, struct GNUNET_HashCode * key) | |||
93 | 122 | ||
94 | 123 | ||
95 | static void | 124 | static void |
96 | put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k) | 125 | do_put (struct CpsRunContext *crc) |
97 | { | 126 | { |
98 | char value[65536]; | 127 | char value[65536]; |
99 | size_t size; | 128 | size_t size; |
100 | struct GNUNET_HashCode key; | 129 | struct GNUNET_HashCode key; |
101 | char *msg; | ||
102 | unsigned int prio; | 130 | unsigned int prio; |
131 | static int i; | ||
103 | 132 | ||
133 | if (PUT_10 == i) | ||
134 | { | ||
135 | i = 0; | ||
136 | crc->phase++; | ||
137 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
138 | return; | ||
139 | } | ||
104 | /* most content is 32k */ | 140 | /* most content is 32k */ |
105 | size = 32 * 1024; | 141 | size = 32 * 1024; |
106 | 142 | ||
@@ -113,36 +149,25 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k) | |||
113 | memset (value, i, size); | 149 | memset (value, i, size); |
114 | if (i > 255) | 150 | if (i > 255) |
115 | memset (value, i - 255, size / 2); | 151 | memset (value, i - 255, size / 2); |
116 | value[0] = k; | 152 | value[0] = crc->i; |
117 | msg = NULL; | ||
118 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 153 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); |
119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
120 | "putting type %u, anon %u under key %s\n", i + 1, i, | 155 | "putting type %u, anon %u under key %s\n", i + 1, i, |
121 | GNUNET_h2s (&key)); | 156 | GNUNET_h2s (&key)); |
122 | if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ , | 157 | crc->api->put (crc->api->cls, &key, size, value, i + 1 /* type */ , |
123 | prio, i /* anonymity */ , | 158 | prio, i /* anonymity */ , |
124 | 0 /* replication */ , | 159 | 0 /* replication */ , |
125 | GNUNET_TIME_relative_to_absolute | 160 | GNUNET_TIME_relative_to_absolute |
126 | (GNUNET_TIME_relative_multiply | 161 | (GNUNET_TIME_relative_multiply |
127 | (GNUNET_TIME_UNIT_MILLISECONDS, | 162 | (GNUNET_TIME_UNIT_MILLISECONDS, |
128 | 60 * 60 * 60 * 1000 + | 163 | 60 * 60 * 60 * 1000 + |
129 | GNUNET_CRYPTO_random_u32 | 164 | GNUNET_CRYPTO_random_u32 |
130 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg)) | 165 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
131 | { | 166 | put_continuation, crc); |
132 | FPRINTF (stderr, "ERROR: `%s'\n", msg); | 167 | i++; |
133 | GNUNET_free_non_null (msg); | ||
134 | return; | ||
135 | } | ||
136 | stored_bytes += size; | ||
137 | stored_ops++; | ||
138 | stored_entries++; | ||
139 | } | 168 | } |
140 | 169 | ||
141 | 170 | ||
142 | static void | ||
143 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
144 | |||
145 | |||
146 | static uint64_t guid; | 171 | static uint64_t guid; |
147 | 172 | ||
148 | 173 | ||
@@ -213,12 +238,20 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
213 | 238 | ||
214 | 239 | ||
215 | static void | 240 | static void |
241 | update_continuation (void *cls, int status, char *msg) | ||
242 | { | ||
243 | struct CpsRunContext *crc = cls; | ||
244 | |||
245 | GNUNET_assert (GNUNET_OK == status); | ||
246 | crc->phase++; | ||
247 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
248 | } | ||
249 | |||
250 | |||
251 | static void | ||
216 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 252 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
217 | { | 253 | { |
218 | struct CpsRunContext *crc = cls; | 254 | struct CpsRunContext *crc = cls; |
219 | int j; | ||
220 | unsigned long long os; | ||
221 | unsigned long long cs; | ||
222 | struct GNUNET_HashCode key; | 255 | struct GNUNET_HashCode key; |
223 | 256 | ||
224 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 257 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
@@ -237,16 +270,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
237 | GNUNET_SCHEDULER_add_now (&cleaning_task, crc); | 270 | GNUNET_SCHEDULER_add_now (&cleaning_task, crc); |
238 | break; | 271 | break; |
239 | case RP_PUT: | 272 | case RP_PUT: |
240 | os = 0; | 273 | do_put (crc); |
241 | for (j = 0; j < PUT_10; j++) | ||
242 | { | ||
243 | put_value (crc->api, j, crc->i); | ||
244 | crc->api->estimate_size (crc->api->cls, &cs); | ||
245 | GNUNET_assert (os <= cs); | ||
246 | os = cs; | ||
247 | } | ||
248 | crc->phase++; | ||
249 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
250 | break; | 274 | break; |
251 | case RP_GET: | 275 | case RP_GET: |
252 | if (crc->cnt == 1) | 276 | if (crc->cnt == 1) |
@@ -261,11 +285,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
261 | GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc); | 285 | GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc); |
262 | break; | 286 | break; |
263 | case RP_UPDATE: | 287 | case RP_UPDATE: |
264 | GNUNET_assert (GNUNET_OK == | 288 | crc->api->update (crc->api->cls, guid, 1, GNUNET_TIME_UNIT_ZERO_ABS, |
265 | crc->api->update (crc->api->cls, guid, 1, | 289 | update_continuation, crc); |
266 | GNUNET_TIME_UNIT_ZERO_ABS, NULL)); | ||
267 | crc->phase++; | ||
268 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
269 | break; | 290 | break; |
270 | 291 | ||
271 | case RP_ITER_ZERO: | 292 | case RP_ITER_ZERO: |