/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ivory.update;
import org.apache.ivory.cluster.util.EmbeddedCluster;
import org.apache.ivory.entity.AbstractTestBase;
import org.apache.ivory.entity.FeedHelper;
import org.apache.ivory.entity.parser.EntityParserFactory;
import org.apache.ivory.entity.parser.FeedEntityParser;
import org.apache.ivory.entity.parser.ProcessEntityParser;
import org.apache.ivory.entity.v0.EntityType;
import org.apache.ivory.entity.v0.Frequency;
import org.apache.ivory.entity.v0.SchemaHelper;
import org.apache.ivory.entity.v0.feed.Feed;
import org.apache.ivory.entity.v0.feed.LocationType;
import org.apache.ivory.entity.v0.feed.Partition;
import org.apache.ivory.entity.v0.feed.Properties;
import org.apache.ivory.entity.v0.feed.Property;
import org.apache.ivory.entity.v0.process.PolicyType;
import org.apache.ivory.entity.v0.process.Process;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class UpdateHelperTest extends AbstractTestBase {
private final FeedEntityParser parser = (FeedEntityParser)
EntityParserFactory.getParser(EntityType.FEED);
private final ProcessEntityParser processParser = (ProcessEntityParser)
EntityParserFactory.getParser(EntityType.PROCESS);
@BeforeClass
public void init() throws Exception {
this.dfsCluster = EmbeddedCluster.newCluster("testCluster", false);
this.conf = dfsCluster.getConf();
setup();
}
@AfterClass
public void tearDown() {
this.dfsCluster.shutdown();
}
@BeforeMethod
public void setUp() throws Exception {
storeEntity(EntityType.CLUSTER, "testCluster");
storeEntity(EntityType.CLUSTER, "backupCluster");
storeEntity(EntityType.FEED, "clicksFeed");
storeEntity(EntityType.FEED, "impressionFeed");
storeEntity(EntityType.FEED, "imp-click-join1");
storeEntity(EntityType.FEED, "imp-click-join2");
}
@Test
public void testShouldUpdate2() throws Exception {
Feed oldFeed = parser.parseAndValidate(this.getClass()
.getResourceAsStream(FEED_XML));
String cluster = "testCluster";
Feed newFeed = (Feed)oldFeed.clone();
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, cluster));
newFeed.setGroups("newgroups");
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, cluster));
newFeed.getLateArrival().setCutOff(Frequency.fromString("hours(8)"));
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, cluster));
newFeed.setFrequency(Frequency.fromString("days(1)"));
Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, cluster));
Process oldProcess = processParser.parseAndValidate(this.getClass().
getResourceAsStream(PROCESS_XML));
Process newProcess = (Process) oldProcess.clone();
newProcess.getRetry().setPolicy(PolicyType.FINAL);
Assert.assertFalse(UpdateHelper.shouldUpdate(oldProcess, newProcess, cluster));
newProcess.getLateProcess().getLateInputs().remove(1);
Assert.assertFalse(UpdateHelper.shouldUpdate(oldProcess, newProcess, cluster));
newProcess.getLateProcess().setPolicy(PolicyType.PERIODIC);
Assert.assertFalse(UpdateHelper.shouldUpdate(oldProcess, newProcess, cluster));
newProcess.setFrequency(Frequency.fromString("days(1)"));
Assert.assertTrue(UpdateHelper.shouldUpdate(oldProcess, newProcess, cluster));
}
@Test
public void testShouldUpdate() throws Exception {
Feed oldFeed = parser.parseAndValidate(this.getClass()
.getResourceAsStream(FEED_XML));
Feed newFeed = (Feed)oldFeed.clone();
Process process = processParser.parseAndValidate(this.getClass().
getResourceAsStream(PROCESS_XML));
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
newFeed.getLateArrival().setCutOff(Frequency.fromString("hours(1)"));
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
newFeed.getLateArrival().setCutOff(oldFeed.getLateArrival().getCutOff());
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
FeedHelper.getLocation(newFeed, LocationType.DATA).setPath("/test");
Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
FeedHelper.getLocation(newFeed, LocationType.DATA).setPath(
FeedHelper.getLocation(oldFeed, LocationType.DATA).getPath());
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
newFeed.setFrequency(Frequency.fromString("months(1)"));
Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
newFeed.setFrequency(oldFeed.getFrequency());
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
Partition partition = new Partition();
partition.setName("1");
newFeed.getPartitions().getPartitions().add(partition);
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
Property property = new Property();
property.setName("1");
property.setValue("1");
newFeed.setProperties(new Properties());
newFeed.getProperties().getProperties().add(property);
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
newFeed.getProperties().getProperties().remove(0);
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
FeedHelper.getCluster(newFeed, process.getClusters().getClusters().get(0).getName()).getValidity().setStart(SchemaHelper.parseDateUTC("2012-11-01T00:00Z"));
Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
FeedHelper.getCluster(newFeed, process.getClusters().getClusters().get(0).getName()).getValidity().
setStart(FeedHelper.getCluster(oldFeed, process.getClusters().getClusters().get(0).getName()).getValidity().getStart());
Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process));
}
}