Example #1
0
int tpgetlev() {
  int rc = tx_info(nullptr);

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

  if (rc == TX_FAIL) {
    TPERROR(TPESYSTEM, "tx_info()=%d", rc);
  } else if (rc == TX_PROTOCOL_ERROR) {
    TPERROR(TPEPROTO, "tx_info()=%d", rc);
  } else {
    TPERROR(TPESYSTEM, "Unexpected tx_info()=%d", rc);
  }
  return -1;
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}