@Override public int getOrAddEventCategory(final String eventCategory, final InternalCallContext context) throws UnableToObtainConnectionException, CallbackFailedException { Integer eventCategoryId = eventCategoriesCache.inverse().get(eventCategory); if (eventCategoryId == null) { eventCategoryId = delegate.getOrAddEventCategory(eventCategory, context); synchronized (eventCategoriesCache) { if (eventCategoriesCache.get(eventCategoryId) == null) { eventCategoriesCache.put(eventCategoryId, eventCategory); } } } return eventCategoryId; }
@VisibleForTesting void convertSamplesToScalarSamples(final String eventType, final Map<String, Object> inputSamples, final Map<Integer, ScalarSample> outputSamples, final InternalCallContext context) { if (inputSamples == null) { return; } final Integer eventCategoryId = timelineDAO.getOrAddEventCategory(eventType, context); for (final String attributeName : inputSamples.keySet()) { final Integer metricId = timelineDAO.getOrAddMetric(eventCategoryId, attributeName, context); final Object sample = inputSamples.get(attributeName); outputSamples.put(metricId, ScalarSample.fromObject(sample)); } }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { Assert.assertTrue(basePath.mkdir()); System.setProperty("killbill.usage.timelines.spoolDir", basePath.getAbsolutePath()); final MeterConfig config = new ConfigurationObjectFactory(System.getProperties()).build(MeterConfig.class); timelineEventHandler = new TimelineEventHandler(config, dao, timelineCoder, sampleCoder, new BackgroundDBChunkWriter(dao, config, internalCallContextFactory), new FileBackedBuffer(config.getSpoolDir(), "TimelineEventHandler", 1024 * 1024, 10)); dao.getOrAddSource(HOST_UUID.toString(), internalCallContext); eventTypeId = dao.getOrAddEventCategory(EVENT_TYPE, internalCallContext); }
System.setProperty("killbill.usage.timelines.spoolDir", basePath.getAbsolutePath()); final MeterConfig config = new ConfigurationObjectFactory(System.getProperties()).build(MeterConfig.class); final int eventTypeId = dao.getOrAddEventCategory(EVENT_TYPE, internalCallContext); final int int2shortId = dao.getOrAddMetric(eventTypeId, "int2short", internalCallContext); final int long2intId = dao.getOrAddMetric(eventTypeId, "long2int", internalCallContext);