flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zentol <...@git.apache.org>
Subject [GitHub] flink pull request #2484: [FLINK-4177] Harden CassandraConnectorTest
Date Fri, 23 Sep 2016 12:19:54 GMT
Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2484#discussion_r80233334
  
    --- Diff: flink-streaming-connectors/flink-connector-cassandra/src/test/java/org/apache/flink/streaming/connectors/cassandra/CassandraConnectorITCase.java
---
    @@ -178,89 +166,122 @@ public static void startCassandra() throws IOException {
     		}
     		scanner.close();
     
    -
    -		// Tell cassandra where the configuration files are.
    -		// Use the test configuration file.
    -		System.setProperty("cassandra.config", tmp.getAbsoluteFile().toURI().toString());
    -
     		if (EMBEDDED) {
    -			cassandra = new EmbeddedCassandraService();
    -			cassandra.start();
    +			String javaCommand = getJavaCommandPath();
    +
    +			// create a logging file for the process
    +			File tempLogFile = File.createTempFile("testlogconfig", "properties");
    +			CommonTestUtils.printLog4jDebugConfig(tempLogFile);
    +
    +			// start the task manager process
    +			String[] command = new String[]{
    +				javaCommand,
    +				"-Dlog.level=DEBUG",
    +				"-Dlog4j.configuration=file:" + tempLogFile.getAbsolutePath(),
    +				"-Dcassandra.config=" + tmp.toURI(),
    +				// these options were taken directly from the jvm.options file in the cassandra repo
    +				"-XX:+UseThreadPriorities",
    +				"-Xss256k",
    +				"-XX:+AlwaysPreTouch",
    +				"-XX:+UseTLAB",
    +				"-XX:+ResizeTLAB",
    +				"-XX:+UseNUMA",
    +				"-XX:+PerfDisableSharedMem",
    +				"-XX:+UseParNewGC",
    +				"-XX:+UseConcMarkSweepGC",
    +				"-XX:+CMSParallelRemarkEnabled",
    +				"-XX:SurvivorRatio=8",
    +				"-XX:MaxTenuringThreshold=1",
    +				"-XX:CMSInitiatingOccupancyFraction=75",
    +				"-XX:+UseCMSInitiatingOccupancyOnly",
    +				"-XX:CMSWaitDuration=10000",
    +				"-XX:+CMSParallelInitialMarkEnabled",
    +				"-XX:+CMSEdenChunksRecordAlways",
    +				"-XX:+CMSClassUnloadingEnabled",
    +
    +				"-classpath", getCurrentClasspath(),
    +				EmbeddedCassandraService.class.getName()
    +			};
    +
    +			ProcessBuilder bld = new ProcessBuilder(command);
    +			cassandra = bld.start();
    +			sw = new StringWriter();
    +			new PipeForwarder(cassandra.getErrorStream(), sw);
     		}
     
    -		try {
    -			Thread.sleep(1000 * 10);
    -		} catch (InterruptedException e) { //give cassandra a few seconds to start up
    +		int attempt = 0;
    +		while (true) {
    +			try {
    +				attempt++;
    +				cluster = builder.getCluster();
    +				session = cluster.connect();
    +				break;
    +			} catch (Exception e) {
    +				if (attempt > 30) {
    +					throw e;
    +				}
    +				try {
    +					Thread.sleep(1000);
    +				} catch (InterruptedException e1) {
    +				}
    +			}
     		}
    -
    -		cluster = builder.getCluster();
    -		session = cluster.connect();
    +		LOG.debug("Connection established after " + attempt + " attempts.");
     
     		session.execute(CREATE_KEYSPACE_QUERY);
    -		session.execute(CREATE_TABLE_QUERY);
    -	}
    -
    -	@BeforeClass
    -	public static void startFlink() throws Exception {
    -		Configuration config = new Configuration();
    -		config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, 4);
    +		session.execute(CREATE_TABLE_QUERY.replace("$TABLE", "flink_initial"));
     
    -		flinkCluster = new ForkableFlinkMiniCluster(config);
    -		flinkCluster.start();
    +		try {
    +			Thread.sleep(5000);
    --- End diff --
    
    the execute() call is synchronous, it's not about making sure that it is complete. I just
found that giving Cassandra a bit of time after creating the keyspace and the first table
resulted in a higher stability.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message