コード例 #1
0
      helper.runInTransaction(agent, function transactionInScope(tx) {
        var transaction = agent.getTransaction()
        t.ok(transaction, "transaction should be visible")
        t.equal(tx, transaction, 'We got the same transaction')
        var colVal = 'Jim'
        var pkVal = 444
        var insQuery = 'INSERT INTO ' + KS + '.' + FAM + ' (' + PK + ',' +  COL
        insQuery += ') VALUES(?, ?);'
        client.executeAsPrepared(insQuery, [pkVal, colVal], function (error, ok) {
          if (error) return t.fail(error)

          t.ok(agent.getTransaction(), "transaction should still be visible")
          t.ok(ok, "everything should be peachy after setting")

          var selQuery = 'SELECT * FROM ' + KS + '.' + FAM + ' WHERE '
          selQuery += PK + ' = ' + pkVal + ';'
          client.execute(selQuery, function (error, value) {
            if (error) return t.fail(error)
            t.ok(agent.getTransaction(), "transaction should still still be visible")
            t.equals(value.rows[0][COL], colVal, "Cassandra client should still work")

            var trace = transaction.trace
            t.ok(trace, "trace should exist")
            t.ok(trace.root, "root element should exist")
            t.equals(trace.root.children.length, 1,
                   "there should be only one child of the root")
            var setSegment = trace.root.children[0]
            t.ok(setSegment, "trace segment for set should exist")
            t.equals(setSegment.name, "Datastore/operation/Cassandra/executeAsPrepared",
                   "should register the executeAsPrepared")
            t.ok(setSegment.children.length >= 1,
                   "set should have a callback segment")
            var getSegment = setSegment.children[0].children[0]
            t.ok(getSegment, "trace segment for get should exist")
            t.equals(getSegment.name, "Datastore/operation/Cassandra/execute",
                   "should register the execute")
            t.ok(getSegment.children.length >= 1,
                   "should have a callback")
            t.ok(getSegment.timer.hrDuration, "trace segment should have ended")

            transaction.end(function() {
              t.end()
            })
          })
        })
      })