kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 30ba5b6fb3ff4fb345ebed90129bb0cc93e3947c92f6e44694f133ef2fdbee1c |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-02 15:59 -06:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-03-09 22:25 +01:00 |
| Parents | 5673627d21a9 |
5 files changed
modified driver-core/pom.xml +1 −0
| @@ -374,6 +374,7 @@ | ||
| 374 | 374 | <skip>false</skip> |
| 375 | 375 | <includes> |
| 376 | 376 | <include>**/SSL*Test.java</include> |
| 377 | + <include>**/UUIDsPID*.java</include> | |
| 377 | 378 | </includes> |
| 378 | 379 | </configuration> |
| 379 | 380 | </plugin> |
added driver-core/src/test/java/com/datastax/driver/core/ClockFactoryTest.java +48 −0
| @@ -0,0 +1,48 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import org.testng.SkipException; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 21 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 22 | + | |
| 23 | +public class ClockFactoryTest { | |
| 24 | + | |
| 25 | + final String osName = System.getProperty("os.name"); | |
| 26 | + | |
| 27 | + @Test(groups = "unit") | |
| 28 | + public void should_use_native_clock_on_unix_platforms() { | |
| 29 | + // Cowardly assume any non-windows platform will support gettimeofday. If we find one that doesn't, | |
| 30 | + // we will have learned something. | |
| 31 | + if (osName.startsWith("Windows")) { | |
| 32 | + throw new SkipException("Skipping test for Windows platforms."); | |
| 33 | + } | |
| 34 | + Clock clock = ClockFactory.newInstance(); | |
| 35 | + assertThat(clock).isInstanceOf(NativeClock.class); | |
| 36 | + assertThat(clock.currentTimeMicros()).isGreaterThan(0); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Test(groups = "unit") | |
| 40 | + public void should_fallback_on_system_clock_on_windows_platforms() { | |
| 41 | + if (!osName.startsWith("Windows")) { | |
| 42 | + throw new SkipException("Skipping test for non-Windows platforms."); | |
| 43 | + } | |
| 44 | + Clock clock = ClockFactory.newInstance(); | |
| 45 | + assertThat(clock).isInstanceOf(SystemClock.class); | |
| 46 | + assertThat(clock.currentTimeMicros()).isGreaterThan(0); | |
| 47 | + } | |
| 48 | +} |
added driver-core/src/test/java/com/datastax/driver/core/utils/UUIDsPIDFromPropertyTest.java +48 −0
| @@ -0,0 +1,48 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core.utils; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.MemoryAppender; | |
| 19 | +import org.apache.log4j.Level; | |
| 20 | +import org.apache.log4j.Logger; | |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | + | |
| 25 | +public class UUIDsPIDFromPropertyTest { | |
| 26 | + | |
| 27 | + private static final Logger logger = Logger.getLogger(UUIDs.class); | |
| 28 | + | |
| 29 | + @Test(groups = "isolated") | |
| 30 | + public void should_obtain_pid_from_system_property() { | |
| 31 | + // If the com.datastax.driver.PID property is set, it should be used and this should be logged. | |
| 32 | + MemoryAppender appender = new MemoryAppender(); | |
| 33 | + Level originalLevel = logger.getLevel(); | |
| 34 | + try { | |
| 35 | + logger.setLevel(Level.INFO); | |
| 36 | + logger.addAppender(appender); | |
| 37 | + int pid = 8675; | |
| 38 | + System.setProperty(UUIDs.PID_SYSTEM_PROPERTY, "" + pid); | |
| 39 | + UUIDs.timeBased(); | |
| 40 | + assertThat(appender.get()) | |
| 41 | + .containsOnlyOnce(String.format("PID obtained from System property %s: %d", | |
| 42 | + UUIDs.PID_SYSTEM_PROPERTY, pid)); | |
| 43 | + } finally { | |
| 44 | + logger.removeAppender(appender); | |
| 45 | + logger.setLevel(originalLevel); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} |
added driver-core/src/test/java/com/datastax/driver/core/utils/UUIDsPIDNativeTest.java +45 −0
| @@ -0,0 +1,45 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core.utils; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.MemoryAppender; | |
| 19 | +import org.apache.log4j.Level; | |
| 20 | +import org.apache.log4j.Logger; | |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | + | |
| 25 | +public class UUIDsPIDNativeTest { | |
| 26 | + | |
| 27 | + private static final Logger logger = Logger.getLogger(UUIDs.class); | |
| 28 | + | |
| 29 | + @Test(groups = "isolated") | |
| 30 | + public void should_obtain_pid_through_native_call() { | |
| 31 | + // In the general case the JNR call should *just* work as most systems should support POSIX getpid. | |
| 32 | + MemoryAppender appender = new MemoryAppender(); | |
| 33 | + Level originalLevel = logger.getLevel(); | |
| 34 | + try { | |
| 35 | + logger.setLevel(Level.INFO); | |
| 36 | + logger.addAppender(appender); | |
| 37 | + UUIDs.timeBased(); | |
| 38 | + | |
| 39 | + assertThat(appender.get()).containsOnlyOnce("PID obtained through native call to getpid()"); | |
| 40 | + } finally { | |
| 41 | + logger.removeAppender(appender); | |
| 42 | + logger.setLevel(originalLevel); | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} |
added driver-core/src/test/java/com/datastax/driver/core/utils/UUIDsPIDPropertyInvalidTest.java +49 −0
| @@ -0,0 +1,49 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core.utils; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.MemoryAppender; | |
| 19 | +import org.apache.log4j.Level; | |
| 20 | +import org.apache.log4j.Logger; | |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | + | |
| 25 | +public class UUIDsPIDPropertyInvalidTest { | |
| 26 | + | |
| 27 | + private static final Logger logger = Logger.getLogger(UUIDs.class); | |
| 28 | + | |
| 29 | + @Test(groups = "isolated") | |
| 30 | + public void should_fallback_on_native_call_if_system_property_invalid() { | |
| 31 | + // If the com.datastax.driver.PID property is set, but is invalid, it should fallback onto native getpid(). | |
| 32 | + MemoryAppender appender = new MemoryAppender(); | |
| 33 | + Level originalLevel = logger.getLevel(); | |
| 34 | + try { | |
| 35 | + logger.setLevel(Level.INFO); | |
| 36 | + logger.addAppender(appender); | |
| 37 | + String pid = "NOT_A_PID"; | |
| 38 | + System.setProperty(UUIDs.PID_SYSTEM_PROPERTY, pid); | |
| 39 | + UUIDs.timeBased(); | |
| 40 | + assertThat(appender.get()) | |
| 41 | + .containsOnlyOnce(String.format("Incorrect integer specified for PID in System property %s: %s", | |
| 42 | + UUIDs.PID_SYSTEM_PROPERTY, pid)) | |
| 43 | + .containsOnlyOnce("PID obtained through native call to getpid()"); | |
| 44 | + } finally { | |
| 45 | + logger.removeAppender(appender); | |
| 46 | + logger.setLevel(originalLevel); | |
| 47 | + } | |
| 48 | + } | |
| 49 | +} |