public static MetricRegistry createRegistryForWALCoprocessor(String clazz) { return MetricRegistries.global().create(createRegistryInfoForWALCoprocessor(clazz)); }
@Test public void testWALObserver() throws IOException { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForWALCoprocessor( CustomWALObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("walEditsCount"); assertTrue(metric.isPresent()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { admin.createTable( new HTableDescriptor(TableName.valueOf(name.getMethodName())) .addFamily(new HColumnDescriptor("foo"))); Counter rollWalRequests = (Counter)metric.get(); long prevCount = rollWalRequests.getCount(); assertTrue(prevCount > 0); try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) { table.put(new Put(foo).addColumn(foo, foo, foo)); } assertEquals(1, rollWalRequests.getCount() - prevCount); } }
@Test public void testWALObserver() throws IOException { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForWALCoprocessor( CustomWALObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("walEditsCount"); assertTrue(metric.isPresent()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { admin.createTable( new HTableDescriptor(TableName.valueOf(name.getMethodName())) .addFamily(new HColumnDescriptor("foo"))); Counter rollWalRequests = (Counter)metric.get(); long prevCount = rollWalRequests.getCount(); assertTrue(prevCount > 0); try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) { table.put(new Put(foo).addColumn(foo, foo, foo)); } assertEquals(1, rollWalRequests.getCount() - prevCount); } }