/*
 * Druid - a distributed column store.
 * Copyright (C) 2012  Metamarkets Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.metamx.druid.master.rules;

import com.metamx.druid.client.DataSegment;
import com.metamx.druid.shard.NoneShardSpec;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.joda.time.Period;
import org.junit.Assert;
import org.junit.Test;

/**
 */
public class PeriodDropRuleTest
{
  private final static DataSegment.Builder builder = DataSegment.builder()
                                                          .dataSource("test")
                                                          .version(new DateTime().toString())
                                                          .shardSpec(new NoneShardSpec());

  @Test
  public void testAppliesToAll()
  {
    DateTime now = new DateTime();
    PeriodDropRule rule = new PeriodDropRule(
        new Period("P5000Y")
    );

    Assert.assertTrue(
        rule.appliesTo(
            builder.interval(
                new Interval(
                    now.minusDays(2),
                    now.minusDays(1)
                )
            ).build(),
            now
        )
    );
    Assert.assertTrue(
        rule.appliesTo(
            builder.interval(new Interval(now.minusYears(100), now.minusDays(1)))
                       .build(),
            now
        )
    );
  }

  @Test
  public void testAppliesToPeriod()
  {
    DateTime now = new DateTime();
    PeriodDropRule rule = new PeriodDropRule(
        new Period("P1M")
    );

    Assert.assertTrue(
        rule.appliesTo(
            builder.interval(new Interval(now.minusWeeks(1), now.minusDays(1)))
                       .build(),
            now
        )
    );
    Assert.assertFalse(
        rule.appliesTo(
            builder.interval(new Interval(now.minusYears(1), now.minusDays(1)))
                       .build(),
            now
        )
    );
    Assert.assertFalse(
        rule.appliesTo(
            builder.interval(new Interval(now.minusMonths(2), now.minusDays(1)))
                       .build(),
            now
        )
    );
  }
}

@@ -1352,16 +1352,37 @@
 ateTime(
+%222012-12-31T01:00:00%22
 ).toStri
@@ -1548,32 +1548,53 @@
  = new DateTime(
+%222012-12-31T01:00:00%22
 );%0A    PeriodDro
@@ -2199,16 +2199,37 @@
 ateTime(
+%222012-12-31T01:00:00%22
 );%0A    P

tested timestamps should be deterministic