Search in sources :

Example 11 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class ObjectStateQuery method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    String uid = null;
    String type = null;
    for (int i = 0; i < args.length; i++) {
        if (args[i].compareTo("-help") == 0) {
            usage();
            System.exit(0);
        } else {
            if (args[i].compareTo("-uid") == 0) {
                uid = args[i + 1];
                i++;
            } else {
                if (args[i].compareTo("-type") == 0) {
                    type = args[i + 1];
                    i++;
                } else {
                    System.out.println("Unknown option " + args[i]);
                    usage();
                    System.exit(0);
                }
            }
        }
    }
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        System.out.println("Status is " + recoveryStore.currentState(new Uid(uid), type));
        InputObjectState buff = new InputObjectState();
        recoveryStore.allObjUids(type, buff, StateStatus.OS_UNCOMMITTED);
        Uid u = UidHelper.unpackFrom(buff);
        System.out.println("got " + u);
    } catch (Exception e) {
        System.err.println("Caught unexpected exception: " + e);
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 12 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class ExposeAllLogsTest method test.

private void test(boolean exposeAllLogsViaJMX) throws Exception {
    RecoveryStore store = StoreManager.getRecoveryStore();
    Set<Uid> uids;
    Map<Uid, ObjectName> uids2 = new HashMap<Uid, ObjectName>();
    JMXServer agent = JMXServer.getAgent();
    // create a record that by default the tooling does not expose
    byte[] data = new byte[10240];
    OutputObjectState state = new OutputObjectState();
    Uid u = new Uid();
    state.packBytes(data);
    assertTrue(store.write_committed(u, FOO_TYPE, state));
    // check that the record is not exposed
    probeObjectStore(false, false);
    // get uids via the object store API
    uids = getUids(store, new HashSet<Uid>(), FOO_TYPE);
    // and validate that there is a uid corresponding to u
    assertTrue(uids.contains(u));
    // get uids via JMX
    getUids(uids2, agent.queryNames(osMBeanName + ",*", null));
    // and validate that there is no MBean corresponding to u
    assertFalse(uids2.containsKey(u));
    // now try the same but tell the browser to expose all log records
    probeObjectStore(true, exposeAllLogsViaJMX);
    // and get the uids for log record MBeans
    uids2.clear();
    getUids(uids2, agent.queryNames(osMBeanName + ",*", null));
    // and validate that there is now an MBean corresponding to u
    assertTrue(uids2.containsKey(u));
    // test that the MBean remove operation works
    agent.getServer().invoke(uids2.get(u), "remove", null, null);
    // check that both the log record and the MBean were removed
    uids.clear();
    getUids(store, uids, FOO_TYPE);
    assertFalse(uids.contains(u));
    uids2.clear();
    getUids(uids2, agent.queryNames(osMBeanName + ",*", null));
    assertFalse(uids2.containsKey(u));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) HashMap(java.util.HashMap) JMXServer(com.arjuna.ats.arjuna.tools.osb.util.JMXServer) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) ObjectName(javax.management.ObjectName) HashSet(java.util.HashSet)

Example 13 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class LogMoveTest method test.

@Test
public void test() {
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    OutputObjectState fluff = new OutputObjectState();
    Uid kungfuTx = new Uid();
    boolean passed = false;
    final String tn = new AtomicAction().type();
    try {
        UidHelper.packInto(kungfuTx, fluff);
        System.err.println("Creating dummy log");
        recoveryStore.write_committed(kungfuTx, tn, fluff);
        if (recoveryStore.currentState(kungfuTx, tn) == StateStatus.OS_COMMITTED) {
            System.err.println("Wrote dummy transaction " + kungfuTx);
            // quicker to deal with scanner directly
            ExpiredTransactionScanner scanner = new ExpiredTransactionScanner(tn, "/StateManager/ExpiredEntries");
            scanner.scan();
            scanner.scan();
            if (recoveryStore.currentState(kungfuTx, tn) == StateStatus.OS_COMMITTED)
                System.err.println("Transaction log not moved!");
            else {
                System.err.println("Transaction log moved!");
                passed = true;
            }
        } else
            System.err.println("State is not committed!");
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
    assertTrue(passed);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ExpiredTransactionScanner(com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionScanner) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Example 14 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class ResourceManagerFailureUnitTest method getUidsCount.

private int getUidsCount() throws Exception {
    final RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    InputObjectState states = new InputObjectState();
    int counter = 0;
    if (recoveryStore.allObjUids(XAResourceRecord.typeName(), states) && states.notempty()) {
        while (UidHelper.unpackFrom(states).notEquals(Uid.nullUid())) {
            counter++;
        }
    }
    return counter;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 15 with RecoveryStore

use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.

the class OTM method getTransactions.

@SuppressWarnings("unchecked")
private synchronized void getTransactions(DefaultMutableTreeNode machineName) {
    removeTransactions();
    scanningNode = machineName;
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(scanningNode);
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState types = new InputObjectState();
        if (recoveryStore.allTypes(types)) {
            String fullPathName = null;
            boolean found = false;
            try {
                boolean endOfList = false;
                DefaultMutableTreeNode currentNode = null;
                DefaultMutableTreeNode currentRoot = top;
                topTran.add(currentRoot);
                while (!endOfList) {
                    fullPathName = types.unpackString();
                    if (fullPathName.compareTo("") == 0)
                        endOfList = true;
                    else {
                        found = true;
                        InputObjectState uids = new InputObjectState();
                        String nodeName = stripName(fullPathName);
                        currentNode = new DefaultMutableTreeNode(nodeName);
                        addDirectory(currentNode, fullPathName);
                        currentRoot = findRoot(top, currentNode);
                        currentRoot.add(currentNode);
                        if (recoveryStore.allObjUids(fullPathName, uids)) {
                            Uid theUid = new Uid(Uid.nullUid());
                            try {
                                boolean endOfUids = false;
                                while (!endOfUids) {
                                    theUid = UidHelper.unpackFrom(uids);
                                    if (theUid.equals(Uid.nullUid()))
                                        endOfUids = true;
                                    else {
                                        DefaultMutableTreeNode tranID = new DefaultMutableTreeNode(theUid.stringForm());
                                        tranID.add(new DefaultMutableTreeNode(new String("status: " + statusToString(recoveryStore.currentState(theUid, fullPathName)))));
                                        currentNode.add(tranID);
                                    }
                                }
                            } catch (Exception e) {
                            // end of uids!
                            }
                        }
                    }
                    if (!found)
                        currentRoot.add(emptyTx);
                }
            } catch (Exception e) {
            // end of list!
            }
        }
    } catch (Exception e) {
        System.err.println(e);
    }
    DefaultTreeModel model = (DefaultTreeModel) transactions.getModel();
    model.reload();
    transactions.repaint();
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) UnknownHostException(java.net.UnknownHostException)

Aggregations

RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)29 Uid (com.arjuna.ats.arjuna.common.Uid)27 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)23 IOException (java.io.IOException)10 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)9 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)8 Test (org.junit.Test)7 XAException (javax.transaction.xa.XAException)5 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)4 XidImple (com.arjuna.ats.jta.xa.XidImple)3 Stack (java.util.Stack)3 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)2 LogStore (com.arjuna.ats.internal.arjuna.objectstore.LogStore)2 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)2 UnknownHostException (java.net.UnknownHostException)2 HashSet (java.util.HashSet)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 HeuristicCommitException (javax.transaction.HeuristicCommitException)2 HeuristicMixedException (javax.transaction.HeuristicMixedException)2