Fix sporadic fail of io.druid.client.CoordinatorServerViewTest

This commit is contained in:
navis.ryu 2015-12-21 11:39:32 +09:00
parent e469655784
commit ad3312171b
3 changed files with 40 additions and 48 deletions

View File

@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import com.fasterxml.jackson.dataformat.smile.SmileGenerator; import com.fasterxml.jackson.dataformat.smile.SmileGenerator;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -109,7 +108,7 @@ public class BrokerServerViewTest extends CuratorTestBase
0 0
); );
setupZNodeForServer(druidServer); setupZNodeForServer(druidServer, zkPathsConfig, jsonMapper);
final DataSegment segment = dataSegmentWithIntervalAndVersion("2014-10-20T00:00:00Z/P1D", "v1"); final DataSegment segment = dataSegmentWithIntervalAndVersion("2014-10-20T00:00:00Z/P1D", "v1");
announceSegmentForServer(druidServer, segment); announceSegmentForServer(druidServer, segment);
@ -179,7 +178,7 @@ public class BrokerServerViewTest extends CuratorTestBase
); );
for (DruidServer druidServer : druidServers) { for (DruidServer druidServer : druidServers) {
setupZNodeForServer(druidServer); setupZNodeForServer(druidServer, zkPathsConfig, jsonMapper);
} }
final List<DataSegment> segments = Lists.transform( final List<DataSegment> segments = Lists.transform(
@ -369,33 +368,6 @@ public class BrokerServerViewTest extends CuratorTestBase
baseView.start(); baseView.start();
} }
private void setupZNodeForServer(DruidServer server) throws Exception
{
final String zNodePathAnnounce = ZKPaths.makePath(announcementsPath, server.getHost());
final String zNodePathSegment = ZKPaths.makePath(inventoryPath, server.getHost());
/*
* Explicitly check whether the zNodes we are about to create exist or not,
* if exist, delete them to make sure we have a clean state on zookeeper.
* Address issue: https://github.com/druid-io/druid/issues/1512
*/
if (curator.checkExists().forPath(zNodePathAnnounce) != null) {
curator.delete().guaranteed().forPath(zNodePathAnnounce);
}
if (curator.checkExists().forPath(zNodePathSegment) != null) {
curator.delete().guaranteed().forPath(zNodePathSegment);
}
curator.create()
.creatingParentsIfNeeded()
.forPath(
zNodePathAnnounce,
jsonMapper.writeValueAsBytes(server.getMetadata())
);
curator.create()
.creatingParentsIfNeeded()
.forPath(zNodePathSegment);
}
private DataSegment dataSegmentWithIntervalAndVersion(String intervalStr, String version) private DataSegment dataSegmentWithIntervalAndVersion(String intervalStr, String version)
{ {
return DataSegment.builder() return DataSegment.builder()

View File

@ -21,7 +21,6 @@ package io.druid.client;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -31,7 +30,6 @@ import com.metamx.common.Pair;
import io.druid.curator.CuratorTestBase; import io.druid.curator.CuratorTestBase;
import io.druid.jackson.DefaultObjectMapper; import io.druid.jackson.DefaultObjectMapper;
import io.druid.query.TableDataSource; import io.druid.query.TableDataSource;
import io.druid.segment.Segment;
import io.druid.server.coordination.DruidServerMetadata; import io.druid.server.coordination.DruidServerMetadata;
import io.druid.server.initialization.ZkPathsConfig; import io.druid.server.initialization.ZkPathsConfig;
import io.druid.timeline.DataSegment; import io.druid.timeline.DataSegment;
@ -49,7 +47,6 @@ import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -100,7 +97,7 @@ public class CoordinatorServerViewTest extends CuratorTestBase
0 0
); );
setupZNodeForServer(druidServer); setupZNodeForServer(druidServer, zkPathsConfig, jsonMapper);
final DataSegment segment = dataSegmentWithIntervalAndVersion("2014-10-20T00:00:00Z/P1D", "v1"); final DataSegment segment = dataSegmentWithIntervalAndVersion("2014-10-20T00:00:00Z/P1D", "v1");
announceSegmentForServer(druidServer, segment); announceSegmentForServer(druidServer, segment);
@ -168,7 +165,7 @@ public class CoordinatorServerViewTest extends CuratorTestBase
); );
for (DruidServer druidServer : druidServers) { for (DruidServer druidServer : druidServers) {
setupZNodeForServer(druidServer); setupZNodeForServer(druidServer, zkPathsConfig, jsonMapper);
} }
final List<DataSegment> segments = Lists.transform( final List<DataSegment> segments = Lists.transform(
@ -350,19 +347,6 @@ public class CoordinatorServerViewTest extends CuratorTestBase
baseView.start(); baseView.start();
} }
private void setupZNodeForServer(DruidServer server) throws Exception
{
curator.create()
.creatingParentsIfNeeded()
.forPath(
ZKPaths.makePath(announcementsPath, server.getHost()),
jsonMapper.writeValueAsBytes(server.getMetadata())
);
curator.create()
.creatingParentsIfNeeded()
.forPath(ZKPaths.makePath(inventoryPath, server.getHost()));
}
private DataSegment dataSegmentWithIntervalAndVersion(String intervalStr, String version) private DataSegment dataSegmentWithIntervalAndVersion(String intervalStr, String version)
{ {
return DataSegment.builder() return DataSegment.builder()

View File

@ -19,12 +19,16 @@
package io.druid.curator; package io.druid.curator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.metamx.common.guava.CloseQuietly; import com.metamx.common.guava.CloseQuietly;
import io.druid.client.DruidServer;
import io.druid.server.initialization.ZkPathsConfig;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime; import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.TestingServer; import org.apache.curator.test.TestingServer;
import org.apache.curator.test.Timing; import org.apache.curator.test.Timing;
import org.apache.curator.utils.ZKPaths;
/** /**
*/ */
@ -49,6 +53,38 @@ public class CuratorTestBase
} }
protected void setupZNodeForServer(DruidServer server, ZkPathsConfig zkPathsConfig, ObjectMapper jsonMapper)
throws Exception
{
final String announcementsPath = zkPathsConfig.getAnnouncementsPath();
final String inventoryPath = zkPathsConfig.getLiveSegmentsPath();
final String zNodePathAnnounce = ZKPaths.makePath(announcementsPath, server.getHost());
final String zNodePathSegment = ZKPaths.makePath(inventoryPath, server.getHost());
/*
* Explicitly check whether the zNodes we are about to create exist or not,
* if exist, delete them to make sure we have a clean state on zookeeper.
* Address issue: https://github.com/druid-io/druid/issues/1512
*/
if (curator.checkExists().forPath(zNodePathAnnounce) != null) {
curator.delete().guaranteed().forPath(zNodePathAnnounce);
}
if (curator.checkExists().forPath(zNodePathSegment) != null) {
curator.delete().guaranteed().forPath(zNodePathSegment);
}
curator.create()
.creatingParentsIfNeeded()
.forPath(
ZKPaths.makePath(announcementsPath, server.getHost()),
jsonMapper.writeValueAsBytes(server.getMetadata())
);
curator.create()
.creatingParentsIfNeeded()
.forPath(ZKPaths.makePath(inventoryPath, server.getHost()));
}
protected void tearDownServerAndCurator() protected void tearDownServerAndCurator()
{ {
CloseQuietly.close(curator); CloseQuietly.close(curator);