Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test read only transaction slots
0003  *
0004  * @file test_nstd_mtest7.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <time.h>
0037 #include <cgreen/cgreen.h>
0038 #include <ndebug.h>
0039 #include <edbutil.h>
0040 #include <signal.h>
0041 #include "exdb.h"
0042 #include "ndebug.h"
0043 
0044 #define E(expr) CHECK((rc = (expr)) == EDB_SUCCESS, #expr)
0045 #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
0046 #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
0047     "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, edb_strerror(rc)), abort()))
0048 
0049 Ensure(test_nstd_mtest7)
0050 {
0051     int rc;
0052     EDB_env *env;
0053     EDB_txn *txn;
0054     char errdet[PATH_MAX];
0055     pid_t pid;
0056     
0057     signal(SIGCHLD, SIG_IGN);
0058     
0059     E(ndrx_mdb_unlink("./testdb", errdet, sizeof(errdet), 
0060             LOG_FACILITY_UBF));
0061    
0062     if (0==(pid=fork()))
0063     {
0064         E(edb_env_create(&env));
0065         E(edb_env_set_maxreaders(env, 1));
0066         E(edb_env_set_mapsize(env, 10485760));
0067         E(edb_env_open(env, "./testdb", 0 /*|EDB_NOSYNC*/, 0664));
0068         E(edb_txn_begin(env, NULL, EDB_RDONLY, &txn));
0069         sleep(9999);
0070     }
0071     
0072     sleep(2);
0073     
0074     E(edb_env_create(&env));
0075     E(edb_env_set_maxreaders(env, 1));
0076     E(edb_env_set_mapsize(env, 10485760));
0077     E(edb_env_open(env, "./testdb", 0 /*|EDB_NOSYNC*/, 0664));
0078     
0079     assert_equal(edb_txn_begin(env, NULL, EDB_RDONLY, &txn), EDB_READERS_FULL);
0080     assert_equal(kill(pid, SIGKILL), EXSUCCEED);
0081     
0082     assert_equal(edb_txn_begin(env, NULL, 0, &txn), EDB_SUCCESS);
0083     
0084     edb_txn_abort(txn);
0085     edb_env_close(env);
0086 
0087     return;
0088 }
0089 
0090 
0091 /**
0092  * Test for read-only transaction capacity recovery
0093  * @return
0094  */
0095 TestSuite *ubf_nstd_mtest7(void)
0096 {
0097     TestSuite *suite = create_test_suite();
0098 
0099     add_test(suite, test_nstd_mtest7);
0100             
0101     return suite;
0102 }
0103 
0104 /* vim: set ts=4 sw=4 et smartindent: */