Skip to content

Commit

Permalink
Merge pull request #938 from calvinjia/tachyon-463
Browse files Browse the repository at this point in the history
[TACHYON-463] Check style in unit tests
  • Loading branch information
haoyuan committed May 16, 2015
2 parents 5b0d6b4 + 3285ea9 commit f77b8bb
Show file tree
Hide file tree
Showing 74 changed files with 688 additions and 556 deletions.
13 changes: 0 additions & 13 deletions build/checkstyle/tachyon_checkstyle_suppressions.xml

This file was deleted.

24 changes: 11 additions & 13 deletions clients/unshaded/src/test/java/tachyon/hadoop/TFSTest.java
Expand Up @@ -4,20 +4,16 @@
* 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 tachyon.hadoop;

import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
package tachyon.hadoop;

import java.io.File;
import java.io.IOException;
Expand All @@ -32,6 +28,8 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.MockClassLoader;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand Down Expand Up @@ -138,16 +136,16 @@ private boolean isHadoop2x() {
}

private void mockTachyonFSGet() throws IOException {
mockStatic(TachyonFS.class);
TachyonFS tachyonFS = mock(TachyonFS.class);
when(TachyonFS.get(eq(mTachyonConf))).thenReturn(tachyonFS);
PowerMockito.mockStatic(TachyonFS.class);
TachyonFS tachyonFS = Mockito.mock(TachyonFS.class);
Mockito.when(TachyonFS.get(Matchers.eq(mTachyonConf))).thenReturn(tachyonFS);
}

private void mockUserGroupInformation() throws IOException {
// need to mock out since FileSystem.get calls UGI, which some times has issues on some systems
mockStatic(UserGroupInformation.class);
final UserGroupInformation ugi = mock(UserGroupInformation.class);
when(ugi.getCurrentUser()).thenReturn(ugi);
PowerMockito.mockStatic(UserGroupInformation.class);
final UserGroupInformation ugi = Mockito.mock(UserGroupInformation.class);
Mockito.when(ugi.getCurrentUser()).thenReturn(ugi);
}

@Before
Expand Down
7 changes: 4 additions & 3 deletions clients/unshaded/src/test/java/tachyon/hadoop/UtilsTest.java
Expand Up @@ -4,14 +4,15 @@
* 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 tachyon.hadoop;

import java.net.URI;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void testGetPathWithoutSchemaThatContainsSchema() {

/**
* This test doesn't work the way you might expect.
*
*
* If you take the URI.create("hdfs://localhost:1234/foo/bar/baz?please=dont&show=up").getPath it
* will return /foo/bar/baz. If you go through Hadoop's Path using {@link Path#Path(String)} then
* Hadoop injects the query params into the path, so when you call toURI it gives a different
Expand Down
45 changes: 23 additions & 22 deletions common/src/test/java/tachyon/PairTest.java
Expand Up @@ -4,14 +4,15 @@
* 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 tachyon;

import org.junit.Assert;
Expand All @@ -21,30 +22,30 @@
* Unit tests for tachyon.Pair
*/
public class PairTest {
private String strType = "test";
private Integer integerType = 7883;
private Long longType = 9887L;
private Double doubleType = 3.14159;
private Boolean boolType = false;
private Character charType = 'a';
private Object[] obj = new Object[6];
private String mStrType = "test";
private Integer mIntegerType = 7883;
private Long mLongType = 9887L;
private Double mDoubleType = 3.14159;
private Boolean mBoolType = false;
private Character mCharType = 'a';
private Object[] mObjs = new Object[6];

@Test
public void constructorTest() {
obj[0] = strType;
obj[1] = integerType;
obj[2] = longType;
obj[3] = doubleType;
obj[4] = boolType;
obj[5] = charType;
mObjs[0] = mStrType;
mObjs[1] = mIntegerType;
mObjs[2] = mLongType;
mObjs[3] = mDoubleType;
mObjs[4] = mBoolType;
mObjs[5] = mCharType;

for (int j = 0; j < obj.length - 1; j ++) {
for (int k = j + 1; k < obj.length; k ++) {
Pair<Object, Object> tPair = new Pair<Object, Object>(obj[j], obj[k]);
Assert.assertEquals(obj[j], tPair.getFirst());
Assert.assertEquals(obj[k], tPair.getSecond());
Assert.assertNotSame(obj[k], tPair.getFirst());
Assert.assertNotSame(obj[j], tPair.getSecond());
for (int j = 0; j < mObjs.length - 1; j ++) {
for (int k = j + 1; k < mObjs.length; k ++) {
Pair<Object, Object> tPair = new Pair<Object, Object>(mObjs[j], mObjs[k]);
Assert.assertEquals(mObjs[j], tPair.getFirst());
Assert.assertEquals(mObjs[k], tPair.getSecond());
Assert.assertNotSame(mObjs[k], tPair.getFirst());
Assert.assertNotSame(mObjs[j], tPair.getSecond());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions common/src/test/java/tachyon/PrefixListTest.java
Expand Up @@ -4,14 +4,15 @@
* 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 tachyon;

import org.junit.Assert;
Expand Down
14 changes: 9 additions & 5 deletions common/src/test/java/tachyon/TachyonURITest.java
Expand Up @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package tachyon;

import org.junit.Assert;
Expand Down Expand Up @@ -163,7 +164,8 @@ public void constructFromParentAndChildTests() {
testParentChild("foo://bar boo:80/foo", "foo://bar boo:80/bar", "/foo");
testParentChild("c:/foo", "foo://bar boo:80/bar", "c:/foo");
testParentChild("c:/foo", "foo://bar boo:80/d:/bar", "c:/foo");
testParentChild("foo://bar boo:80/c:/foo", "foo://bar boo:80/d:/bar", "foo://bar boo:80/c:/foo");
testParentChild("foo://bar boo:80/c:/foo", "foo://bar boo:80/d:/bar",
"foo://bar boo:80/c:/foo");
}

@Test
Expand Down Expand Up @@ -194,7 +196,8 @@ public void equalsTests() {
TachyonURI[] uriFromDifferentConstructor =
new TachyonURI[] {new TachyonURI("tachyon://127.0.0.1:8080/a/b/c.txt"),
new TachyonURI("tachyon", "127.0.0.1:8080", "/a/b/c.txt"),
new TachyonURI(new TachyonURI("tachyon://127.0.0.1:8080/a"), new TachyonURI("b/c.txt"))};
new TachyonURI(
new TachyonURI("tachyon://127.0.0.1:8080/a"), new TachyonURI("b/c.txt"))};
for (int i = 0; i < uriFromDifferentConstructor.length - 1; i ++) {
Assert.assertTrue(uriFromDifferentConstructor[i].equals(uriFromDifferentConstructor[i + 1]));
}
Expand All @@ -203,7 +206,8 @@ public void equalsTests() {
@Test
public void getAuthorityTests() {
String[] authorities =
new String[] {"localhost", "localhost:8080", "127.0.0.1", "127.0.0.1:8080", "localhost", null};
new String[] {"localhost", "localhost:8080", "127.0.0.1", "127.0.0.1:8080", "localhost",
null};
for (String authority : authorities) {
TachyonURI uri = new TachyonURI("file", authority, "/a/b");
Assert.assertEquals(authority, uri.getAuthority());
Expand Down Expand Up @@ -370,11 +374,11 @@ public void joinTests() {
Assert.assertEquals(new TachyonURI("C:\\\\a\\b"),
new TachyonURI("C:\\\\a").join(new TachyonURI("\\b")));

final String pathWithSpecialChar = "����,��b����$o\u0005����[\u000F| \u009E=B����";
final String pathWithSpecialChar = "����,��b����$o����[| =B����";
Assert.assertEquals(new TachyonURI("/" + pathWithSpecialChar),
new TachyonURI("/").join(pathWithSpecialChar));

final String pathWithSpecialCharAndColon = "����,��b����$o\u0005����[\u000F| \u009E=B��:��";
final String pathWithSpecialCharAndColon = "����,��b����$o����[| =B��:��";
Assert.assertEquals(new TachyonURI("/" + pathWithSpecialCharAndColon),
new TachyonURI("/").join(pathWithSpecialCharAndColon));
}
Expand Down
8 changes: 4 additions & 4 deletions common/src/test/java/tachyon/conf/TachyonConfTest.java
Expand Up @@ -19,11 +19,11 @@ public class TachyonConfTest {
private static final String DEFAULT_HADOOP_UFS_PREFIX = "hdfs://,s3://,s3n://,glusterfs:///";

private static TachyonConf sDefaultTachyonConf;
private static final Map<String, String> sTestProperties = new LinkedHashMap<String, String>();
private static Map<String, String> sTestProperties = new LinkedHashMap<String, String>();

private TachyonConf mCustomPropsTachyonConf;
private TachyonConf mSystemPropsTachyonConf;

@AfterClass
public static void afterClass() {
System.clearProperty(Constants.MASTER_HOSTNAME);
Expand All @@ -42,7 +42,7 @@ public static void beforeClass() {
sTestProperties.put("recursive", "${multiplesubs}");
sTestProperties.put("home.port", "8080");
sTestProperties.put("complex.address", "tachyon://${home}:${home.port}");

// initialize the system properties
System.setProperty(Constants.MASTER_HOSTNAME, "master");
System.setProperty(Constants.MASTER_PORT, "20001");
Expand Down Expand Up @@ -248,7 +248,7 @@ public void testVariableSubstitutionRecursive() {
String recursive = mCustomPropsTachyonConf.get("recursive", null);
Assert.assertTrue(multiplesubs.equals(recursive));
}

@Test
public void testSystemVariableSubstitutionSample() {
String masterAddress = mSystemPropsTachyonConf.get(Constants.MASTER_ADDRESS, null);
Expand Down
5 changes: 3 additions & 2 deletions common/src/test/java/tachyon/conf/UtilsTest.java
Expand Up @@ -4,14 +4,15 @@
* 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 tachyon.conf;

import org.junit.Assert;
Expand Down
Expand Up @@ -4,9 +4,9 @@
* 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
Expand All @@ -33,19 +33,19 @@ public void largeRetriesProducePositiveTime() {
}

public static final class MockExponentialBackoffRetry extends ExponentialBackoffRetry {
private int retryCount = 0;
private int mRetryCount = 0;

public MockExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepMs, int maxRetries) {
super(baseSleepTimeMs, maxSleepMs, maxRetries);
}

@Override
public int getRetryCount() {
return retryCount;
return mRetryCount;
}

public void setRetryCount(int retryCount) {
this.retryCount = retryCount;
this.mRetryCount = retryCount;
}
}
}
1 change: 1 addition & 0 deletions common/src/test/java/tachyon/util/CommonUtilsTest.java
Expand Up @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package tachyon.util;

import org.junit.Assert;
Expand Down
5 changes: 3 additions & 2 deletions common/src/test/java/tachyon/util/NetworkUtilsTest.java
Expand Up @@ -4,14 +4,15 @@
* 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 tachyon.util;

import java.net.InetSocketAddress;
Expand Down
Expand Up @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package tachyon.client;

import java.io.IOException;
Expand Down
Expand Up @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package tachyon.client;

import java.io.IOException;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class FileInStreamIntegrationTest {
private static TachyonFS sTfs = null;

@Rule
public ExpectedException thrown = ExpectedException.none();
public ExpectedException mThrown = ExpectedException.none();

@AfterClass
public static final void afterClass() throws Exception {
Expand Down Expand Up @@ -228,8 +229,8 @@ public void seekExceptionTest1() throws IOException {
*/
@Test
public void seekExceptionTest2() throws IOException {
thrown.expect(IOException.class);
thrown.expectMessage("Seek position is past EOF");
mThrown.expect(IOException.class);
mThrown.expectMessage("Seek position is past EOF");
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
Expand Down
Expand Up @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package tachyon.client;

import java.io.IOException;
Expand Down

0 comments on commit f77b8bb

Please sign in to comment.