diff --git a/tests/integration/predis/test_basic_reporting_disabled.php b/tests/integration/predis/test_basic_reporting_disabled.php new file mode 100644 index 000000000..0567f878a --- /dev/null +++ b/tests/integration/predis/test_basic_reporting_disabled.php @@ -0,0 +1,98 @@ + $REDIS_HOST, 'port' => $REDIS_PORT)); +try { + $client->connect(); +} catch (Exception $e) { + die("skip: " . $e->getMessage() . "\n"); +} + +$key = uniqid(__FILE__, true); +tap_equal(0, $client->exists($key), 'key does not exist'); + +$client->set($key, 1); +$client->incr($key); +tap_equal('2', $client->get($key), 'get key'); + +$client->del($key); + +// Test that we did not generate datastore instance metadata. +$txn = new Transaction; +foreach ($txn->getTrace()->findSegmentsByName('Datastore/operation/Redis/set') as $segment) { + tap_equal(null, $segment->getDatastoreInstance(), 'no instance metadata found'); + break; +} diff --git a/tests/integration/predis/test_instance_basic.php b/tests/integration/predis/test_instance_basic.php new file mode 100644 index 000000000..6d600bf7a --- /dev/null +++ b/tests/integration/predis/test_instance_basic.php @@ -0,0 +1,82 @@ + $REDIS_HOST, 'port' => $REDIS_PORT, 'database' => 7)); +try { + $client->connect(); +} catch (Exception $e) { + die("skip: " . $e->getMessage() . "\n"); +} + +$key = uniqid(__FILE__, true); +tap_equal(0, $client->exists($key), 'key does not exist'); + +$client->set($key, 1); +$client->incr($key); +tap_equal('2', $client->get($key), 'get key'); + +$client->del($key); + +$txn = new Transaction; +foreach ($txn->getTrace()->findSegmentsWithDatastoreInstances() as $segment) { + $instance = $segment->getDatastoreInstance(); + tap_assert($instance->isHost($REDIS_HOST), 'instance host matches'); + tap_equal((string) $REDIS_PORT, (string) $instance->portPathOrId, 'instance port matches'); + tap_equal("7", (string) $instance->databaseName, 'instance database matches'); +} diff --git a/tests/integration/predis/test_txn_restarted.php b/tests/integration/predis/test_txn_restarted.php new file mode 100644 index 000000000..caa713af5 --- /dev/null +++ b/tests/integration/predis/test_txn_restarted.php @@ -0,0 +1,120 @@ + $REDIS_HOST, 'port' => $REDIS_PORT, 'database' => 0)); + +// Force predis to connect - usually it will lazily connect as needed. +// In this case the 'select' operation will still be captured because +// the connection wont occur until the 'exists' operation is executed +// below. +// Following code forces predis to connect now and therefore 'select' +// operation happens before transaction is ended below and so will not +// appear in the operations metrics +try { + $client->connect(); +} catch (Exception $e) { + die("skip: " . $e->getMessage() . "\n"); +} + +// Restart the transaction. If you compare the expected metrics in this test to +// test_basic.php, you'll note that the detection metrics go away (because +// they're thrown away with the initial transaction), but we still look for the +// Redis datastore metrics created by the $client method calls below. +$appname = ini_get("newrelic.appname"); +$license = ini_get("newrelic.license"); +newrelic_set_appname($appname, $license, false); + +$key = uniqid(__FILE__, true); +tap_equal(0, $client->exists($key), 'key does not exist'); + +$client->set($key, 1); +$client->incr($key); +tap_equal('2', $client->get($key), 'get key'); + +$client->del($key); + +// Test that we did not generate datastore instance metadata. +$txn = new Transaction; +foreach ($txn->getTrace()->findSegmentsByName('Datastore/operation/Redis/set') as $segment) { + tap_equal(null, $segment->getDatastoreInstance(), 'no instance metadata found'); + break; +}