@@ -0,0 +1,3370 @@
+package com.rackspacecloud.blueflood.io.datastax;%0A%0Aimport com.datastax.driver.core.BoundStatement;%0Aimport com.rackspacecloud.blueflood.types.IMetric;%0Aimport com.rackspacecloud.blueflood.types.Locator;%0Aimport com.rackspacecloud.blueflood.types.Metric;%0Aimport com.rackspacecloud.blueflood.utils.Clock;%0Aimport com.rackspacecloud.blueflood.utils.DefaultClockImpl;%0Aimport com.rackspacecloud.blueflood.utils.TimeValue;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport static org.mockito.Mockito.*;%0Aimport static org.junit.Assert.*;%0A%0A/**%0A * Unit tests for DBasicMetricsRW class and its parent class DAbstractMetricsRW.%0A */%0Apublic class DBasicMetricsRWTest %7B%0A%0A    private DLocatorIO locatorIO = mock(DLocatorIO.class);%0A    private DDelayedLocatorIO delayedLocatorIO = mock(DDelayedLocatorIO.class);%0A%0A    @Test%0A    public void metricCollectedADayAgo_shouldBeDelayed() throws Exception %7B%0A        Clock clock = new DefaultClockImpl();%0A        TimeValue aDay = new TimeValue(1, TimeUnit.DAYS);%0A        DBasicMetricsRW metricsRW = new DBasicMetricsRW(locatorIO, delayedLocatorIO, false, clock);%0A        IMetric metric = new Metric(Locator.createLocatorFromPathComponents(%22123456%22, %22foo.bar%22),%0A                                    987L, clock.now().getMillis() - aDay.toMillis(),%0A                                    aDay, null);%0A        assertTrue(%22a day old metric is delayed%22, metricsRW.isDelayed(metric));%0A    %7D%0A%0A    @Test%0A    public void onTimeMetric_shouldNotBeDelayed() throws Exception %7B%0A        Clock clock = new DefaultClockImpl();%0A        TimeValue aDay = new TimeValue(1, TimeUnit.DAYS);%0A        DBasicMetricsRW metricsRW = new DBasicMetricsRW(locatorIO, delayedLocatorIO, false, clock);%0A        IMetric metric = new Metric(Locator.createLocatorFromPathComponents(%22123456%22, %22foo.bar%22),%0A                987L, clock.now().getMillis(),%0A                aDay, null);%0A        assertFalse(%22on time metric is not delayed%22, metricsRW.isDelayed(metric));%0A    %7D%0A%0A    @Test%0A    public void delayedMetric_shouldGetBoundStatement() throws Exception %7B%0A        Clock clock = new DefaultClockImpl();%0A        TimeValue aDay = new TimeValue(1, TimeUnit.DAYS);%0A%0A        DBasicMetricsRW metricsRW = new DBasicMetricsRW(locatorIO, delayedLocatorIO, false, clock);%0A        Locator locator = Locator.createLocatorFromPathComponents(%22123456%22, %22foo.bar%22);%0A        IMetric metric = new Metric(locator,%0A                987L, clock.now().getMillis() - aDay.toMillis(),%0A                aDay, null);%0A        when(delayedLocatorIO.getBoundStatementForLocator(any(), anyInt(), eq(locator))).thenReturn(mock(BoundStatement.class));%0A        assertNotNull(%22delayed metric should get a boundStatement%22, metricsRW.getBoundStatementForMetricIfDelayed(metric));%0A    %7D%0A%0A    @Test%0A    public void onTimeMetric_shouldNotGetBoundStatement() throws Exception %7B%0A        Clock clock = new DefaultClockImpl();%0A        TimeValue aDay = new TimeValue(1, TimeUnit.DAYS);%0A%0A        DBasicMetricsRW metricsRW = new DBasicMetricsRW(locatorIO, delayedLocatorIO, false, clock);%0A        IMetric metric = new Metric(Locator.createLocatorFromPathComponents(%22123456%22, %22foo.bar%22),%0A                987L, clock.now().getMillis(),%0A                aDay, null);%0A        assertNull(%22on time metric should NOT get a boundStatement%22, metricsRW.getBoundStatementForMetricIfDelayed(metric));%0A    %7D%0A%7D%0A

add unit tests for DBasicMetricsRW