~jheiss/galera/galera

« back to all changes in this revision

Viewing changes to gcs/src/unit_tests/gcs_state_msg_test.c

  • Committer: Alex Yurchenko
  • Date: 2011-08-20 23:37:05 UTC
  • Revision ID: ayurchen@void-20110820233705-532t7g9ip8ss24sv
References lp:828648 - synced with SVN branch 0.8 r2321

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// Copyright (C) 2007 Codership Oy <info@codership.com>
2
2
 
3
 
// $Id: gcs_state_msg_test.c 2204 2011-06-22 20:48:58Z alex $
 
3
// $Id: gcs_state_msg_test.c 2308 2011-08-15 07:33:07Z alex $
4
4
 
5
5
#include <check.h>
6
6
#include <string.h>
56
56
    fail_if (send_state->flags          != recv_state->flags);
57
57
    fail_if (send_state->gcs_proto_ver  != recv_state->gcs_proto_ver);
58
58
    fail_if (send_state->repl_proto_ver != recv_state->repl_proto_ver);
59
 
    fail_if (send_state->appl_proto_ver == recv_state->appl_proto_ver);
60
 
    fail_if (recv_state->appl_proto_ver != 0, "appl_proto_ver: %d",
61
 
             recv_state->appl_proto_ver); // V0 does not have appl proto field
 
59
    fail_if (send_state->appl_proto_ver != recv_state->appl_proto_ver);
 
60
    fail_if (recv_state->appl_proto_ver != 1, "appl_proto_ver: %d",
 
61
             recv_state->appl_proto_ver);
62
62
    fail_if (send_state->act_seqno      != recv_state->act_seqno,
63
63
             "act_seqno: sent %lld, recv %lld",
64
64
             send_state->act_seqno, recv_state->act_seqno);
87
87
}
88
88
END_TEST
89
89
 
90
 
START_TEST (gcs_state_msg_test_quorum)
91
 
{
92
 
    gcs_state_msg_t* st1, *st2, *st3;
93
 
    gu_uuid_t        g1, g2, g3;
94
 
 
95
 
    gu_uuid_generate (&g1, NULL, 0);
96
 
    gu_uuid_generate (&g2, NULL, 0);
97
 
    gu_uuid_generate (&g3, NULL, 0);
98
 
 
99
 
    st1 = st2 = st3 = NULL;
100
 
 
101
 
    mark_point();
 
90
START_TEST (gcs_state_msg_test_quorum_inherit)
 
91
{
 
92
    gcs_state_msg_t* st[3] = { NULL, };
 
93
 
 
94
    gu_uuid_t state_uuid;
 
95
    gu_uuid_t group1_uuid, group2_uuid;
 
96
    gu_uuid_t prim1_uuid, prim2_uuid;
 
97
 
 
98
    gu_uuid_generate (&state_uuid,  NULL, 0);
 
99
    gu_uuid_generate (&group1_uuid, NULL, 0);
 
100
    gu_uuid_generate (&group2_uuid, NULL, 0);
 
101
    gu_uuid_generate (&prim1_uuid,  NULL, 0);
 
102
    gu_uuid_generate (&prim2_uuid,  NULL, 0);
 
103
 
 
104
    gcs_seqno_t prim1_seqno = 123;
 
105
    gcs_seqno_t prim2_seqno = 834;
 
106
 
 
107
    gcs_seqno_t act1_seqno = 345;
 
108
    gcs_seqno_t act2_seqno = 239472508908LL;
 
109
 
 
110
    gcs_state_quorum_t quorum;
 
111
 
 
112
    mark_point();
 
113
 
 
114
    /* First just nodes from different groups and configurations, none JOINED */
 
115
    st[0] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim2_uuid,
 
116
                                  5, prim2_seqno - 1, act2_seqno - 1,
 
117
                                  GCS_NODE_STATE_PRIM, GCS_NODE_STATE_PRIM,
 
118
                                  "node0", "",
 
119
                                  0, 1, 1, 0);
 
120
    fail_if(NULL == st[0]);
 
121
 
 
122
    st[1] = gcs_state_msg_create (&state_uuid, &group1_uuid, &prim1_uuid,
 
123
                                  3, prim1_seqno, act1_seqno,
 
124
                                  GCS_NODE_STATE_PRIM, GCS_NODE_STATE_PRIM,
 
125
                                  "node1", "",
 
126
                                  0, 1, 0, 0);
 
127
    fail_if(NULL == st[1]);
 
128
 
 
129
    st[2] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim2_uuid,
 
130
                                  5, prim2_seqno, act2_seqno,
 
131
                                  GCS_NODE_STATE_PRIM, GCS_NODE_STATE_PRIM,
 
132
                                  "node2", "",
 
133
                                  0, 1, 1, 1);
 
134
    fail_if(NULL == st[2]);
 
135
 
 
136
    gu_info ("                  Inherited 1");
 
137
    int ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
138
                                        sizeof(st)/sizeof(gcs_state_msg_t*),
 
139
                                        &quorum);
 
140
    fail_if (0 != ret);
 
141
    fail_if (1 != quorum.version);
 
142
    fail_if (false != quorum.primary);
 
143
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &GU_UUID_NIL));
 
144
    fail_if (GCS_SEQNO_ILL != quorum.act_id);
 
145
    fail_if (GCS_SEQNO_ILL != quorum.conf_id);
 
146
    fail_if (-1 != quorum.gcs_proto_ver);
 
147
    fail_if (-1 != quorum.repl_proto_ver);
 
148
    fail_if (-1 != quorum.appl_proto_ver);
 
149
 
 
150
    /* now make node1 inherit PC */
 
151
    gcs_state_msg_destroy (st[1]);
 
152
    st[1] = gcs_state_msg_create (&state_uuid, &group1_uuid, &prim1_uuid,
 
153
                                  3, prim1_seqno, act1_seqno,
 
154
                                  GCS_NODE_STATE_JOINED, GCS_NODE_STATE_DONOR,
 
155
                                  "node1", "",
 
156
                                  0, 1, 0, 0);
 
157
    fail_if(NULL == st[1]);
 
158
 
 
159
    gu_info ("                  Inherited 2");
 
160
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
161
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
162
                                    &quorum);
 
163
    fail_if (0 != ret);
 
164
    fail_if (1 != quorum.version);
 
165
    fail_if (true != quorum.primary);
 
166
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &group1_uuid));
 
167
    fail_if (act1_seqno  != quorum.act_id);
 
168
    fail_if (prim1_seqno != quorum.conf_id);
 
169
    fail_if (0 != quorum.gcs_proto_ver);
 
170
    fail_if (1 != quorum.repl_proto_ver);
 
171
    fail_if (0 != quorum.appl_proto_ver);
 
172
 
 
173
    /* now make node0 inherit PC (should yield conflicting uuids) */
 
174
    gcs_state_msg_destroy (st[0]);
 
175
    st[0] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim2_uuid,
 
176
                                  5, prim2_seqno - 1, act2_seqno - 1,
 
177
                                  GCS_NODE_STATE_SYNCED, GCS_NODE_STATE_SYNCED,
 
178
                                  "node0", "",
 
179
                                  0, 1, 1, 0);
 
180
    fail_if(NULL == st[0]);
 
181
 
 
182
    gu_info ("                  Inherited 3");
 
183
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
184
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
185
                                    &quorum);
 
186
    fail_if (0 != ret);
 
187
    fail_if (1 != quorum.version);
 
188
    fail_if (false != quorum.primary);
 
189
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &GU_UUID_NIL));
 
190
    fail_if (GCS_SEQNO_ILL != quorum.act_id);
 
191
    fail_if (GCS_SEQNO_ILL != quorum.conf_id);
 
192
    fail_if (-1 != quorum.gcs_proto_ver);
 
193
    fail_if (-1 != quorum.repl_proto_ver);
 
194
    fail_if (-1 != quorum.appl_proto_ver);
 
195
 
 
196
    /* now make node1 non-joined again: group2 should win */
 
197
    gcs_state_msg_destroy (st[1]);
 
198
    st[1] = gcs_state_msg_create (&state_uuid, &group1_uuid, &prim1_uuid,
 
199
                                  3, prim1_seqno, act1_seqno,
 
200
                                  GCS_NODE_STATE_JOINED, GCS_NODE_STATE_PRIM,
 
201
                                  "node1", "",
 
202
                                  0, 1, 0, 0);
 
203
    fail_if(NULL == st[1]);
 
204
 
 
205
    gu_info ("                  Inherited 4");
 
206
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
207
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
208
                                    &quorum);
 
209
    fail_if (0 != ret);
 
210
    fail_if (1 != quorum.version);
 
211
    fail_if (true != quorum.primary);
 
212
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &group2_uuid));
 
213
    fail_if (act2_seqno - 1 != quorum.act_id);
 
214
    fail_if (prim2_seqno - 1 != quorum.conf_id);
 
215
    fail_if (0 != quorum.gcs_proto_ver);
 
216
    fail_if (1 != quorum.repl_proto_ver);
 
217
    fail_if (0 != quorum.appl_proto_ver);
 
218
 
 
219
    /* now make node2 joined: it should become a representative */
 
220
    gcs_state_msg_destroy (st[2]);
 
221
    st[2] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim2_uuid,
 
222
                                  5, prim2_seqno, act2_seqno,
 
223
                                  GCS_NODE_STATE_SYNCED, GCS_NODE_STATE_SYNCED,
 
224
                                  "node2", "",
 
225
                                  0, 1, 1, 0);
 
226
    fail_if(NULL == st[2]);
 
227
 
 
228
    gu_info ("                  Inherited 5");
 
229
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
230
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
231
                                    &quorum);
 
232
    fail_if (0 != ret);
 
233
    fail_if (1 != quorum.version);
 
234
    fail_if (true != quorum.primary);
 
235
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &group2_uuid));
 
236
    fail_if (act2_seqno != quorum.act_id);
 
237
    fail_if (prim2_seqno != quorum.conf_id);
 
238
    fail_if (0 != quorum.gcs_proto_ver);
 
239
    fail_if (1 != quorum.repl_proto_ver);
 
240
    fail_if (0 != quorum.appl_proto_ver);
 
241
 
 
242
    gcs_state_msg_destroy (st[0]);
 
243
    gcs_state_msg_destroy (st[1]);
 
244
    gcs_state_msg_destroy (st[2]);
 
245
}
 
246
END_TEST
 
247
 
 
248
START_TEST (gcs_state_msg_test_quorum_remerge)
 
249
{
 
250
    gcs_state_msg_t* st[3] = { NULL, };
 
251
 
 
252
    gu_uuid_t state_uuid;
 
253
    gu_uuid_t group1_uuid, group2_uuid;
 
254
    gu_uuid_t prim0_uuid, prim1_uuid, prim2_uuid;
 
255
 
 
256
    gu_uuid_generate (&state_uuid,  NULL, 0);
 
257
    gu_uuid_generate (&group1_uuid, NULL, 0);
 
258
    gu_uuid_generate (&group2_uuid, NULL, 0);
 
259
    gu_uuid_generate (&prim0_uuid,  NULL, 0);
 
260
    gu_uuid_generate (&prim1_uuid,  NULL, 0);
 
261
    gu_uuid_generate (&prim2_uuid,  NULL, 0);
 
262
 
 
263
    gcs_seqno_t prim1_seqno = 123;
 
264
    gcs_seqno_t prim2_seqno = 834;
 
265
 
 
266
    gcs_seqno_t act1_seqno = 345;
 
267
    gcs_seqno_t act2_seqno = 239472508908LL;
 
268
 
 
269
    gcs_state_quorum_t quorum;
 
270
 
 
271
    mark_point();
 
272
 
 
273
    /* First just nodes from different groups and configurations, none JOINED */
 
274
    st[0] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim0_uuid,
 
275
                                  5, prim2_seqno - 1, act2_seqno - 1,
 
276
                                  GCS_NODE_STATE_JOINER,GCS_NODE_STATE_NON_PRIM,
 
277
                                  "node0", "",
 
278
                                  0, 1, 1, 0);
 
279
    fail_if(NULL == st[0]);
 
280
 
 
281
    st[1] = gcs_state_msg_create (&state_uuid, &group1_uuid, &prim1_uuid,
 
282
                                  3, prim1_seqno, act1_seqno,
 
283
                                  GCS_NODE_STATE_JOINER,GCS_NODE_STATE_NON_PRIM,
 
284
                                  "node1", "",
 
285
                                  0, 1, 0, 0);
 
286
    fail_if(NULL == st[1]);
 
287
 
 
288
    st[2] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim2_uuid,
 
289
                                  5, prim2_seqno, act2_seqno,
 
290
                                  GCS_NODE_STATE_JOINER,GCS_NODE_STATE_NON_PRIM,
 
291
                                  "node2", "",
 
292
                                  0, 1, 1, 1);
 
293
    fail_if(NULL == st[2]);
 
294
 
 
295
    gu_info ("                  Remerged 1");
 
296
    int ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
297
                                        sizeof(st)/sizeof(gcs_state_msg_t*),
 
298
                                        &quorum);
 
299
    fail_if (0 != ret);
 
300
    fail_if (1 != quorum.version);
 
301
    fail_if (false != quorum.primary);
 
302
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &GU_UUID_NIL));
 
303
    fail_if (GCS_SEQNO_ILL != quorum.act_id);
 
304
    fail_if (GCS_SEQNO_ILL != quorum.conf_id);
 
305
    fail_if (-1 != quorum.gcs_proto_ver);
 
306
    fail_if (-1 != quorum.repl_proto_ver);
 
307
    fail_if (-1 != quorum.appl_proto_ver);
 
308
 
 
309
    /* Now make node0 to be joined at least once */
 
310
    gcs_state_msg_destroy (st[0]);
 
311
    st[0] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim0_uuid,
 
312
                                  5, prim2_seqno - 1, act2_seqno - 1,
 
313
                                  GCS_NODE_STATE_DONOR, GCS_NODE_STATE_NON_PRIM,
 
314
                                  "node0", "",
 
315
                                  0, 1, 1, 0);
 
316
    fail_if(NULL == st[0]);
 
317
 
 
318
    gu_info ("                  Remerged 2");
 
319
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
320
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
321
                                    &quorum);
 
322
    fail_if (0 != ret);
 
323
    fail_if (1 != quorum.version);
 
324
    fail_if (true != quorum.primary);
 
325
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &group2_uuid));
 
326
    fail_if (act2_seqno - 1 != quorum.act_id);
 
327
    fail_if (prim2_seqno - 1 != quorum.conf_id);
 
328
    fail_if (0 != quorum.gcs_proto_ver);
 
329
    fail_if (1 != quorum.repl_proto_ver);
 
330
    fail_if (0 != quorum.appl_proto_ver);
 
331
 
 
332
    /* Now make node2 to be joined too */
 
333
    gcs_state_msg_destroy (st[2]);
 
334
    st[2] = gcs_state_msg_create (&state_uuid, &group2_uuid, &prim2_uuid,
 
335
                                  5, prim2_seqno, act2_seqno,
 
336
                                  GCS_NODE_STATE_JOINED,GCS_NODE_STATE_NON_PRIM,
 
337
                                  "node2", "",
 
338
                                  0, 1, 1, 1);
 
339
    fail_if(NULL == st[2]);
 
340
 
 
341
    gu_info ("                  Remerged 3");
 
342
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
343
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
344
                                    &quorum);
 
345
    fail_if (0 != ret);
 
346
    fail_if (1 != quorum.version);
 
347
    fail_if (true != quorum.primary);
 
348
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &group2_uuid));
 
349
    fail_if (act2_seqno != quorum.act_id);
 
350
    fail_if (prim2_seqno != quorum.conf_id);
 
351
    fail_if (0 != quorum.gcs_proto_ver);
 
352
    fail_if (1 != quorum.repl_proto_ver);
 
353
    fail_if (0 != quorum.appl_proto_ver);
 
354
 
 
355
    /* now make node1 joined too: conflict */
 
356
    gcs_state_msg_destroy (st[1]);
 
357
    st[1] = gcs_state_msg_create (&state_uuid, &group1_uuid, &prim1_uuid,
 
358
                                  3, prim1_seqno, act1_seqno,
 
359
                                  GCS_NODE_STATE_SYNCED,GCS_NODE_STATE_NON_PRIM,
 
360
                                  "node1", "",
 
361
                                  0, 1, 0, 0);
 
362
    fail_if(NULL == st[1]);
 
363
 
 
364
    gu_info ("                  Remerged 4");
 
365
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
366
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
367
                                    &quorum);
 
368
    fail_if (0 != ret);
 
369
    fail_if (1 != quorum.version);
 
370
    fail_if (false != quorum.primary);
 
371
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &GU_UUID_NIL));
 
372
    fail_if (GCS_SEQNO_ILL != quorum.act_id);
 
373
    fail_if (GCS_SEQNO_ILL != quorum.conf_id);
 
374
    fail_if (-1 != quorum.gcs_proto_ver);
 
375
    fail_if (-1 != quorum.repl_proto_ver);
 
376
    fail_if (-1 != quorum.appl_proto_ver);
 
377
 
 
378
    /* now make node1 current joiner: should be ignored */
 
379
    gcs_state_msg_destroy (st[1]);
 
380
    st[1] = gcs_state_msg_create (&state_uuid, &group1_uuid, &prim1_uuid,
 
381
                                  3, prim1_seqno, act1_seqno,
 
382
                                  GCS_NODE_STATE_SYNCED, GCS_NODE_STATE_JOINER,
 
383
                                  "node1", "",
 
384
                                  0, 1, 0, 0);
 
385
    fail_if(NULL == st[1]);
 
386
 
 
387
    gu_info ("                  Remerged 5");
 
388
    ret = gcs_state_msg_get_quorum ((const gcs_state_msg_t**)st,
 
389
                                    sizeof(st)/sizeof(gcs_state_msg_t*),
 
390
                                    &quorum);
 
391
    fail_if (0 != ret);
 
392
    fail_if (1 != quorum.version);
 
393
    fail_if (true != quorum.primary);
 
394
    fail_if (0 != gu_uuid_compare(&quorum.group_uuid, &group2_uuid));
 
395
    fail_if (act2_seqno != quorum.act_id);
 
396
    fail_if (prim2_seqno != quorum.conf_id);
 
397
    fail_if (0 != quorum.gcs_proto_ver);
 
398
    fail_if (1 != quorum.repl_proto_ver);
 
399
    fail_if (0 != quorum.appl_proto_ver);
 
400
 
 
401
    gcs_state_msg_destroy (st[0]);
 
402
    gcs_state_msg_destroy (st[1]);
 
403
    gcs_state_msg_destroy (st[2]);
102
404
}
103
405
END_TEST
104
406
 
105
407
Suite *gcs_state_msg_suite(void)
106
408
{
107
409
  Suite *s  = suite_create("GCS state message");
108
 
  TCase *tc = tcase_create("gcs_state_msg");
109
 
 
110
 
  suite_add_tcase (s, tc);
111
 
  tcase_add_test  (tc, gcs_state_msg_test_basic);
112
 
  tcase_add_test  (tc, gcs_state_msg_test_quorum);
 
410
  TCase *tc_basic   = tcase_create("gcs_state_msg_basic");
 
411
  TCase *tc_inherit = tcase_create("gcs_state_msg_inherit");
 
412
  TCase *tc_remerge = tcase_create("gcs_state_msg_remerge");
 
413
 
 
414
  suite_add_tcase (s, tc_basic);
 
415
  tcase_add_test  (tc_basic, gcs_state_msg_test_basic);
 
416
 
 
417
  suite_add_tcase (s, tc_inherit);
 
418
  tcase_add_test  (tc_inherit, gcs_state_msg_test_quorum_inherit);
 
419
 
 
420
  suite_add_tcase (s, tc_remerge);
 
421
  tcase_add_test  (tc_remerge, gcs_state_msg_test_quorum_remerge);
 
422
 
113
423
  return s;
114
424
}
115
425