Esempio n. 1
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, test_rc;
    int rmid1 = 2, rmid2 = 3;

    if (argc < 2) {
        fprintf(stderr, "%s: at least one option must be specified\n",
                argv[0]);
        exit (1);
    }
    test_rc = strtol(argv[1], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid1, rc = lixa_monkeyrm_call_ax_reg(rmid1));
    assert(TMER_PROTO == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid2, rc = lixa_monkeyrm_call_ax_reg(rmid2));
    assert(TMER_PROTO == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_PROTOCOL_ERROR == rc);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(test_rc == rc);

    if (TX_OK != test_rc) {
        printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
        assert(TX_OK == rc);
    }

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);

    /* memory leak prevention */
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    lixa_monkeyrm_call_cleanup();
    
    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, test_rc, chained;;
    int rmid = 1;
    
    if (argc < 3) {
        fprintf(stderr, "%s: at least two options must be specified\n",
                argv[0]);
        exit (1);
    }
    chained = strtol(argv[1], NULL, 0);
    test_rc = strtol(argv[2], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(TX_PROTOCOL_ERROR == rc);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);

    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(TX_PROTOCOL_ERROR == rc);

    if (chained) {
        printf("%s| tx_set_transaction_control(): %d\n", pgm,
               rc = tx_set_transaction_control(TX_CHAINED));
        assert(TX_OK == rc);
    }
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid, rc = lixa_monkeyrm_call_ax_reg(rmid));
    assert(TM_OK == rc);

    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(test_rc == rc);

    if (TX_FAIL != test_rc) {
        printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
        assert(TX_OK == rc);
    }

    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 3
0
/* Called once when the server is started. Creates and opens the databases. */
int
tpsvrinit(int argc, char* argv[])
{
	int ret;
	int dbflags = DB_AUTO_COMMIT | DB_CREATE | DB_THREAD;

	progname = argv[0];
	if (verbose)
		printf("%s: called\n", progname);

	/* Open resource managers. */
	if (tx_open() == TX_ERROR) {
		fprintf(stderr, "tx_open: TX_ERROR\n");
		return (-1);
	}

	/* Seed random number generator. */
	srand((u_int)(time(NULL) | getpid()));

	/* Open XA database handles. */
	if ((ret = db_create(&db1, NULL, DB_XA_CREATE)) != 0) {
		fprintf(stderr, "db_create: %s\n", db_strerror(ret));
		return (-1);
	}
	db1->set_errfile(db1, stderr);
	if ((ret = db1->open(db1, NULL,
	    TABLE1, NULL, DB_BTREE, dbflags, 0660)) != 0) {
		fprintf(stderr, "DB open: %s: %s\n", TABLE1, db_strerror(ret));
		return (-1);
	}
	if ((ret = db_create(&db2, NULL, DB_XA_CREATE)) != 0) {
		fprintf(stderr, "db_create: %s\n", db_strerror(ret));
		return (-1);
	}
	db2->set_errfile(db2, stderr);
	if ((ret = db2->open(db2, NULL,
	    TABLE2, NULL, DB_BTREE, dbflags, 0660)) != 0) {
		fprintf(stderr, "DB open: %s: %s\n", TABLE2, db_strerror(ret));
		return (-1);
	}

	if (verbose)
		printf("%s: tpsvrinit: initialization done\n", progname);

	return (0);
}
Esempio n. 4
0
int tpopen() {
  if (false) {
    TPERROR(TPEPROTO, "tx_open called from client");
    return -1;
  }

  int rc = tx_open();

  if (rc == TX_OK) {
    f*x::atmi::reset_tperrno();
    return 0;
  }

  if (rc == TX_ERROR || rc == TX_FAIL) {
    TPERROR(TPERMERR, "tx_open()=%d", rc);
  } else {
    TPERROR(TPESYSTEM, "Unexpected tx_open()=%d", rc);
  }
  return -1;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc;
    int tx_open_rc, tx_close_rc;

    if (argc < 3) {
        fprintf(stderr, "%s: at least two options must be specified\n",
                argv[0]);
        exit (1);
    }
    tx_open_rc = strtol(argv[1], NULL, 0);
    tx_close_rc = strtol(argv[2], NULL, 0);
    
    printf("%s| starting...\n", pgm);
    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(tx_open_rc == rc);
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    assert(tx_close_rc == rc);
    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, test_rc;
    
    if (argc < 2) {
        fprintf(stderr, "%s: at least one option must be specified\n",
                argv[0]);
        exit (1);
    }

    test_rc = strtol(argv[1], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(test_rc == rc);

    if (TX_OK == test_rc) {
        printf("%s| tx_rollback(): %d\n", pgm, rc = tx_rollback());
        assert(TX_OK == rc);
    }

    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    if (TX_FAIL == test_rc)
        assert(TX_FAIL == test_rc);
    else
        assert(TX_OK == rc);

    /* memory leak prevention */
    lixa_tx_close_cleanup();
    lixa_monkeyrm_call_cleanup();
    
    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, test_rc, xaopen;
    
    if (argc < 3) {
        fprintf(stderr, "%s: at least two options must be specified\n",
                argv[0]);
        exit (1);
    }

    xaopen = strtol(argv[1], NULL, 0);
    test_rc = strtol(argv[2], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    if (xaopen)
        assert(test_rc == rc);
    else
        assert(TX_OK == rc);

    if (xaopen && TX_OK == test_rc) {
        printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
        assert(TX_OK == rc);
    } else if (!xaopen) {
        printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
        assert(test_rc == rc);
    }
    
    /* memory leak prevention */
    lixa_tx_close_cleanup();
    lixa_monkeyrm_call_cleanup();

    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, commit, test_rc;
    
    if (argc < 3) {
        fprintf(stderr, "%s: at least two options must be specified\n",
                argv[0]);
        exit (1);
    }
    commit = strtol(argv[1], NULL, 0);
    test_rc = strtol(argv[2], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);

    if (commit)
        printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    else
        printf("%s| tx_rollback(): %d\n", pgm, rc = tx_rollback());        
    assert(test_rc == rc);

    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    if (TX_FAIL == test_rc) {
        assert(TX_FAIL == rc);
        lixa_tx_close_cleanup();
    } else
        assert(TX_OK == rc);

    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc;
    long begin_pos;
    int rmid;

    if (argc < 2) {
        fprintf(stderr, "%s: at least one option must be specified\n",
                argv[0]);
        exit (1);
    }
    begin_pos = strtol(argv[1], NULL, 0);
    
    printf("%s| starting...\n", pgm);
    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);

    if (0 == begin_pos) {
        printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
        assert(TX_OK == rc);
    }
    
    /* emulate callback registration from resource manager when accessing
     * resource manager owned resources; you may imagine these are the
     * equivalent of a SQLExecDirect function call */
    for (rmid=0; rmid<3; ++rmid) {
        printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
               pgm, rmid, rc = lixa_monkeyrm_call_ax_reg(rmid));
    }
    
    if (1 == begin_pos) {
        printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
        assert(TX_OUTSIDE == rc);
    }
    
    /* emulate callback de-registration from resource manager when accessing
     * resource manager owned resources; you may imagine these are the
     * equivalent of a SQLEndTran function call */
    for (rmid=0; rmid<3; ++rmid) {
        printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
               pgm, rmid, rc = lixa_monkeyrm_call_ax_unreg(rmid));
        if (0 == begin_pos)
            assert(TMER_PROTO == rc);
    }
    
    if (2 == begin_pos) {
        printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
        assert(TX_OK == rc);
    }
    
    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    if (1 == begin_pos)
        assert(TX_PROTOCOL_ERROR == rc);
    else
        assert(TX_OK == rc);

    /* emulate callback registration from resource manager when accessing
     * resource manager owned resources; you may imagine these are the
     * equivalent of a SQLExecDirect function call */
    for (rmid=0; rmid<3; ++rmid) {
        printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
               pgm, rmid, rc = lixa_monkeyrm_call_ax_reg(rmid));
        assert(TM_OK == rc);
    }
    
    /* emulate callback de-registration from resource manager when accessing
     * resource manager owned resources; you may imagine these are the
     * equivalent of a SQLEndTran function call */
    for (rmid=0; rmid<3; ++rmid) {
        printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
               pgm, rmid, rc = lixa_monkeyrm_call_ax_unreg(rmid));
        assert(TM_OK == rc);
    }
    
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    assert(TX_OK == rc);

    /* memory leak prevention */
    lixa_monkeyrm_call_cleanup();    

    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
    /* generic variables */
    int         txrc;
    /* PostgreSQL variables */
    PGconn     *conn;
    PGresult   *res;
    /* control variables */
    int         commit;
    int         insert;
    int         test_rc;
    
    if (argc < 4) {
        fprintf(stderr, "%s: at least two options must be specified\n",
                argv[0]);
        exit (1);
    }
    commit = strtol(argv[1], NULL, 0);
    insert = strtol(argv[2], NULL, 0);
    test_rc = strtol(argv[3], NULL, 0);

    /* open the resource manager(s) */
    if (TX_OK != (txrc = tx_open())) {
        fprintf(stderr, "tx_open error: %d\n", txrc);
        exit(txrc);
    }

    /* retrieve the connection handler */
    conn = lixa_pq_get_conn();
    if (NULL == conn) {
        fprintf(stderr, "lixa_pq_get_conn: conn is NULL\n");
        exit(1);
    }

    /* trivial check for lixa_pq_is_managed_conn() function */
    if (!lixa_pq_is_managed_conn(conn)) {
        fprintf(stderr, "lixa_pq_is_managed_conn: returned FALSE, this "
                "should be impossible!\n");
        exit(1);
    }
    
    /* start a new transaction */
    if (TX_OK != (txrc = tx_begin())) {
        fprintf(stderr, "tx_begin error: %d\n", txrc);
        exit(txrc);
    }

    /* insert data */
    if (insert) {
        res = PQexec(
            conn, "INSERT INTO authors VALUES(9, 'Name', 'Surname');");
        if (PGRES_COMMAND_OK != PQresultStatus(res)) {
            fprintf(stderr,
                    "INSERT INTO authors: %s", PQerrorMessage(conn));
            PQclear(res);
            exit_nicely(conn);
        }
        PQclear(res);
    } else {
        res = PQexec(
            conn, "DELETE FROM authors;");
        if (PGRES_COMMAND_OK != PQresultStatus(res)) {
            fprintf(stderr,
                    "DELETE FROM authors: %s", PQerrorMessage(conn));
            PQclear(res);
            exit_nicely(conn);
        }
        PQclear(res);
    }
    
    /* commit transaction */
    if (commit) {
        if (test_rc != (txrc = tx_commit())) {
            fprintf(stderr, "tx_commit error: %d instead of %d\n",
                    txrc, test_rc);
            exit(txrc);
        }
    } else {
        if (test_rc != (txrc = tx_rollback())) {
            fprintf(stderr, "tx_rollback error: %d instead of %d\n",
                    txrc, test_rc);
            exit(txrc);
        }
    }

    /* close the resource manager */
    if (TX_OK != (txrc = tx_close())) {
        fprintf(stderr, "tx_close error: %d\n", txrc);
        exit(txrc);
    }

    return 0;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    TXINFO info;
    int rc;
    
    printf("%s| starting...\n", pgm);

    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(TX_COMMIT_COMPLETED));
    assert(TX_PROTOCOL_ERROR == rc);
    
    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);
    
    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(333));
    assert(TX_EINVAL == rc);
    
    printf("%s| tx_info(): %d\n", pgm, tx_info(&info));
    assert(TX_COMMIT_COMPLETED == info.when_return);
    
    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(TX_COMMIT_COMPLETED));
    assert(TX_OK == rc);
    
    printf("%s| tx_info(): %d\n", pgm, tx_info(&info));
    assert(TX_COMMIT_COMPLETED == info.when_return);
    
    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(TX_COMMIT_DECISION_LOGGED));
    assert(TX_NOT_SUPPORTED == rc);
    
    printf("%s| tx_info(): %d\n", pgm, tx_info(&info));
    assert(TX_COMMIT_COMPLETED == info.when_return);
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);
    
    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(TX_COMMIT_COMPLETED));
    assert(TX_OK == rc);
    
    printf("%s| tx_info(): %d\n", pgm, tx_info(&info));
    assert(TX_COMMIT_COMPLETED == info.when_return);
    
    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(TX_COMMIT_DECISION_LOGGED));
    assert(TX_NOT_SUPPORTED == rc);
    
    printf("%s| tx_info(): %d\n", pgm, tx_info(&info));
    assert(TX_COMMIT_COMPLETED == info.when_return);
    
    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(TX_OK == rc);
    
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    assert(TX_OK == rc);
    
    /* memory leak prevention */
    lixa_monkeyrm_call_cleanup();    

    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    TXINFO info;
    int rc;
    long fail_point;

    if (argc < 2) {
        fprintf(stderr, "%s: at least one option must be specified\n",
                argv[0]);
        exit(1);
    }

    fail_point = strtol(argv[1], NULL, 0);
    
    printf("%s| starting...\n", pgm);
    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    if (0 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);
    
    printf("%s| tx_set_transaction_control(): %d\n", pgm,
           rc = tx_set_transaction_control(TX_UNCHAINED));
    if (0 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);

    printf("%s| tx_set_commit_return(): %d\n", pgm,
           rc = tx_set_commit_return(TX_COMMIT_COMPLETED));
    if (0 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);
    
    printf("%s| tx_set_transaction_timeout(): %d\n", pgm,
           rc = tx_set_transaction_timeout(1));
    if (0 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);
    
    printf("%s| tx_info(): %d\n", pgm, tx_info(&info));
    if (0 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);
    
    if (0 == fail_point) {
        printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
        assert(TX_FAIL == rc);
        printf("%s| tx_rollback(): %d\n", pgm, rc = tx_rollback());
        assert(TX_FAIL == rc);
        printf("%s| ...finished (TX_FAIL)\n", pgm);
        /* memory leak prevention */
        lixa_monkeyrm_call_cleanup();
        return 0;
    }
    
    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    if (1 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    if (1 == fail_point) {
        assert(TX_FAIL == rc);
        printf("%s| ...finished (TX_FAIL)\n", pgm);
        /* memory leak prevention */
        lixa_monkeyrm_call_cleanup();
        return 0;
    } else
        assert(TX_OK == rc);
    
    printf("%s| tx_rollback(): %d\n", pgm, rc = tx_rollback());
    if (2 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);

    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    if (2 == fail_point) {
        assert(TX_FAIL == rc);
        printf("%s| ...finished (TX_FAIL)\n", pgm);
        /* memory leak prevention */
        lixa_monkeyrm_call_cleanup();
        return 0;
    } else
        assert(TX_OK == rc);
    
    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);
    
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    if (3 == fail_point)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);
    
    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    if (3 == fail_point) {
        assert(TX_FAIL == rc);
        printf("%s| ...finished (TX_FAIL)\n", pgm);
        exit(0);
    } else
        assert(TX_OK == rc);
    
    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, test_rc;
    int rmid = 2;
    
    if (argc < 2) {
        fprintf(stderr, "%s: at least one option must be specified\n",
                argv[0]);
        exit (1);
    }
    test_rc = strtol(argv[1], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_PROTOCOL_ERROR == rc);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(TX_OK == rc);
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_PROTOCOL_ERROR == rc);

    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(TX_OK == rc);
    
    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid, rc = lixa_monkeyrm_call_ax_reg(rmid));
    assert(TM_OK == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OUTSIDE == rc);

    printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
           pgm, rmid, rc = lixa_monkeyrm_call_ax_unreg(rmid));
    assert(TM_OK == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);

    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(TX_OK == rc);
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(test_rc == rc);
    if (TX_FAIL == test_rc) {
        /* test can not go on after TX_FAIL */
        /* memory leak prevention */
        lixa_monkeyrm_call_cleanup();    
        printf("%s| ...finished\n", pgm);
        return 0;
    }
    
    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid, rc = lixa_monkeyrm_call_ax_reg(rmid));
    assert(TM_OK == rc);

    printf("%s| tx_commit(): %d\n", pgm, rc = tx_commit());
    assert(TX_OK == rc);
    
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    assert(TX_OK == rc);

    /* memory leak prevention */
    lixa_monkeyrm_call_cleanup();    

    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 14
0
void *transaction(void *parm)
{
    int rc;
    TXINFO info;
    struct timeval to;
    struct thread_data_s *data = (struct thread_data_s *)parm;
    
    printf("%s| tx_open(): %d\n", data->pgm, rc = tx_open());
    assert(TX_OK == rc);
    if (data->rnd) {
        to.tv_sec = 0;
        to.tv_usec = random() % data->rnd;
        printf("%s| waiting %ld us\n", data->pgm, to.tv_usec);
        select(0, NULL, NULL, NULL, &to);
    }
    printf("%s| tx_begin(): %d\n", data->pgm, rc = tx_begin());
    assert(TX_OK == rc);
    if (data->rnd) {
        to.tv_sec = 0;
        to.tv_usec = random() % data->rnd;
        printf("%s| waiting %ld us\n", data->pgm, to.tv_usec);
        select(0, NULL, NULL, NULL, &to);
    }
    printf("%s| tx_info(): %d\n", data->pgm, rc = tx_info(&info));
    assert(1 == rc);
    
    /* emulate callback registration from resource manager when accessing
     * resource manager owned resources; you may imagine these are the
     * equivalent of a SQLExecDirect function call */
    if (data->rnd) {
        to.tv_sec = 0;
        to.tv_usec = random() % data->rnd;
        printf("%s| waiting %ld us\n", data->pgm, to.tv_usec);
        select(0, NULL, NULL, NULL, &to);
    }
    lixa_monkeyrm_call_ax_reg(2);
    if (data->rnd) {
        to.tv_sec = 0;
        to.tv_usec = random() % data->rnd;
        printf("%s| waiting %ld us\n", data->pgm, to.tv_usec);
        select(0, NULL, NULL, NULL, &to);
    }
    lixa_monkeyrm_call_ax_reg(3);
    
    if (data->rnd) {
        to.tv_sec = 0;
        to.tv_usec = random() % data->rnd;
        printf("%s| waiting %ld us\n", data->pgm, to.tv_usec);
        select(0, NULL, NULL, NULL, &to);
    }
    if (data->commit)
        printf("%s| tx_commit(): %d\n", data->pgm, rc = tx_commit());
    else
        printf("%s| tx_rollback(): %d\n", data->pgm, rc = tx_rollback());
    assert(data->expected_rc == rc);
    
    if (data->rnd) {
        to.tv_sec = 0;
        to.tv_usec = random() % data->rnd;
        printf("%s| waiting %ld us\n", data->pgm, to.tv_usec);
        select(0, NULL, NULL, NULL, &to);
    }
    printf("%s| tx_close(): %d\n", data->pgm, rc = tx_close());
    if (TX_FAIL == data->expected_rc)
        assert(TX_FAIL == rc);
    else
        assert(TX_OK == rc);

    return NULL;
}
Esempio n. 15
0
int main(int argc, char *argv[])
{
    char *pgm = argv[0];
    int rc, test_rc;
    int rmid1 = 2, rmid2 = 3;
    
    if (argc < 2) {
        fprintf(stderr, "%s: at least one option must be specified\n",
                argv[0]);
        exit (1);
    }
    test_rc = strtol(argv[1], NULL, 0);

    printf("%s| starting...\n", pgm);

    printf("%s| tx_open(): %d\n", pgm, rc = tx_open());
    assert(test_rc == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, 0, rc = lixa_monkeyrm_call_ax_reg(0));
    assert(TMER_TMERR == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid1, rc = lixa_monkeyrm_call_ax_reg(rmid1));
    assert(TM_OK == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid1, rc = lixa_monkeyrm_call_ax_reg(rmid1));
    assert(TMER_PROTO == rc);

    printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
           pgm, rmid1, rc = lixa_monkeyrm_call_ax_unreg(rmid1));
    assert(TM_OK == rc);

    printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
           pgm, rmid1, rc = lixa_monkeyrm_call_ax_unreg(rmid1));
    assert(TMER_PROTO == rc);

    printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
           pgm, rmid2, rc = lixa_monkeyrm_call_ax_unreg(rmid2));
    assert(TMER_PROTO == rc);

    printf("%s| tx_begin(): %d\n", pgm, rc = tx_begin());
    assert(TX_OK == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid2, rc = lixa_monkeyrm_call_ax_reg(rmid2));
    assert(TM_OK == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, rmid2, rc = lixa_monkeyrm_call_ax_reg(rmid2));
    assert(TMER_PROTO == rc);

    printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
           pgm, rmid2, rc = lixa_monkeyrm_call_ax_unreg(rmid2));
    assert(TMER_PROTO == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, 1, rc = lixa_monkeyrm_call_ax_reg(1));
    assert(TMER_TMERR == rc);

    printf("%s| lixa_monkeyrm_call_ax_reg(%d): %d\n",
           pgm, 4, rc = lixa_monkeyrm_call_ax_reg(4));
    assert(TMER_INVAL == rc);

    printf("%s| lixa_monkeyrm_call_ax_unreg(%d): %d\n",
           pgm, 4, rc = lixa_monkeyrm_call_ax_unreg(4));
    assert(TMER_INVAL == rc);

    printf("%s| tx_rollback(): %d\n", pgm, rc = tx_rollback());
    assert(TX_OK == rc);
    
    printf("%s| tx_close(): %d\n", pgm, rc = tx_close());
    assert(TX_OK == rc);

    lixa_monkeyrm_call_cleanup();
        
    printf("%s| ...finished\n", pgm);
    return 0;
}
Esempio n. 16
0
int main(int argc, char *argv[])
{
    /* generic variables */
    int txrc;
    /* IBM DB2 variables */
    SQLRETURN rc_cli = SQL_SUCCESS;
    SQLHANDLE env, conn, stat;
    char db_name[] = "sample";
    char user[] = "";
    char passwd[] = "";
    SQLCHAR sql_stat_i[] = "INSERT INTO DB2INST1.DEPT "
        "(DEPTNO, DEPTNAME, ADMRDEPT) "
        "VALUES('Z99', 'RESEARCH & DEVELOPMENT', 'E01')";
    SQLCHAR sql_stat_d[] = "DELETE DB2INST1.DEPT WHERE DEPTNO='Z99'";
    SQLCHAR *sql_stat = NULL;
    /* control variables */
    int         commit;
    int         insert;
    int         test_rc;

    if (argc < 4) {
        fprintf(stderr, "%s: at least three options must be specified\n",
                argv[0]);
        exit (1);
    }
    commit = strtol(argv[1], NULL, 0);
    insert = strtol(argv[2], NULL, 0);
    test_rc = strtol(argv[3], NULL, 0);

    /* open the resource manager(s) */
    if (TX_OK != (txrc = tx_open())) {
        fprintf(stderr, "tx_open error: %d\n", txrc);
        exit(txrc);
    }

    if (SQL_SUCCESS != (rc_cli = SQLAllocHandle(
                            SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env))) {
        fprintf(stderr, "Unable to allocate the environment handle: %d\n",
                rc_cli);
        exit(1);
    }

    if (SQL_SUCCESS != (rc_cli = SQLSetEnvAttr(
                           env, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3,
                           0))) {
        fprintf(stderr, "Unable to set ODBC version 3.0: %d\n", rc_cli);
        exit(1);
    }
    
    if (SQL_SUCCESS != (rc_cli = SQLAllocHandle(
                            SQL_HANDLE_DBC, env, &conn))) {
        fprintf(stderr, "Unable to allocate the connection handle: %d\n",
                rc_cli);
        exit(1);
    }

    if (SQL_SUCCESS != (rc_cli = SQLSetConnectAttr(
                            conn, SQL_ATTR_AUTOCOMMIT,
                            (SQLPOINTER)SQL_AUTOCOMMIT_OFF,
                            SQL_NTS))) {
        fprintf(stderr, "Unable to set autocommit (OFF) attribute: %d\n",
                rc_cli);
        exit(1);
    }

    if (SQL_SUCCESS != (rc_cli = SQLConnect(
                           conn, (SQLCHAR *)db_name, SQL_NTS,
                           (SQLCHAR *)user, SQL_NTS,
                           (SQLCHAR *)passwd, SQL_NTS))) {
        fprintf(stderr, "Unable to connect to database '%s': %d\n",
                db_name, rc_cli);
        exit(1);
    }

    if (SQL_SUCCESS != (rc_cli = SQLAllocHandle(
                            SQL_HANDLE_STMT, conn, &stat))) {
        fprintf(stderr, "Unable to allocate the statement handle: %d\n",
                rc_cli);
        exit(1);
    }
    
    if (TX_OK != (txrc = tx_begin())) {
        fprintf(stderr, "tx_begin error: %d\n", txrc);
        exit(txrc);
    }

    /* insert data */
    if (insert) {
        if (SQL_SUCCESS != (rc_cli = SQLExecDirect(
                                stat, sql_stat_i, SQL_NTS))) {
            fprintf(stderr, "Unable to execute the SQL statement ('%s'): %d\n",
                    sql_stat_i, rc_cli);
            exit(1);
        }
    } else {
        if (SQL_SUCCESS != (rc_cli = SQLExecDirect(
                                stat, sql_stat_d, SQL_NTS))) {
            fprintf(stderr, "Unable to execute the SQL statement ('%s'): %d\n",
                    sql_stat_d, rc_cli);
            exit(1);
        }
    }

    /* commit transaction */
    if (commit) {
        if (test_rc != (txrc = tx_commit())) {
            fprintf(stderr, "tx_commit error: %d\n", txrc);
            exit(txrc);
        }
    } else {
        if (test_rc != (txrc = tx_rollback())) {
            fprintf(stderr, "tx_rollback error: %d\n", txrc);
            exit(txrc);
        }
    }
    
    if (SQL_SUCCESS != (rc_cli = SQLFreeHandle(SQL_HANDLE_STMT, stat))) {
        fprintf(stderr, "Unable to free the statement handle: %d\n",
                rc_cli);
        exit(1);
    }
    
    if (SQL_SUCCESS != (rc_cli = SQLDisconnect(conn))) {
        fprintf(stderr, "Unable to disconnect from database '%s': %d\n",
                db_name, rc_cli);
        exit(1);
    }
    
    if (SQL_SUCCESS != (rc_cli = SQLFreeHandle(SQL_HANDLE_DBC, conn))) {
        fprintf(stderr, "Unable to free the connection handle: %d\n",
                rc_cli);
        exit(1);
    }
    
    if (SQL_SUCCESS != (rc_cli = SQLFreeHandle(SQL_HANDLE_ENV, env))) {
        fprintf(stderr, "Unable to free the environment handle: %d\n",
                rc_cli);
        exit(1);
    }
    
    /* close the resource manager(s) */
    if (TX_OK != (txrc = tx_close())) {
        fprintf(stderr, "tx_close error: %d\n", txrc);
        exit(txrc);
    }
    
    return 0;
}