-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PARQUET-777: Move dynamic support classes, add tests.
- Loading branch information
Showing
8 changed files
with
864 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
parquet-common/src/main/java/org/apache/parquet/Exceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.parquet; | ||
|
||
public class Exceptions { | ||
/** | ||
* If the given throwable is an instance of E, throw it as an E. | ||
*/ | ||
public static <E extends Exception> void throwIfInstance(Throwable t, | ||
Class<E> excClass) | ||
throws E { | ||
if (excClass.isAssignableFrom(t.getClass())) { | ||
// the throwable is already an exception, so return it | ||
throw excClass.cast(t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
parquet-common/src/test/java/org/apache/parquet/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.parquet; | ||
|
||
import org.junit.Assert; | ||
import java.util.concurrent.Callable; | ||
|
||
public class TestUtils { | ||
|
||
/** | ||
* A convenience method to avoid a large number of @Test(expected=...) tests | ||
* @param message A String message to describe this assertion | ||
* @param expected An Exception class that the Runnable should throw | ||
* @param callable A Callable that is expected to throw the exception | ||
*/ | ||
public static void assertThrows( | ||
String message, Class<? extends Exception> expected, Callable callable) { | ||
try { | ||
callable.call(); | ||
Assert.fail("No exception was thrown (" + message + "), expected: " + | ||
expected.getName()); | ||
} catch (Exception actual) { | ||
try { | ||
Assert.assertEquals(message, expected, actual.getClass()); | ||
} catch (AssertionError e) { | ||
e.addSuppressed(actual); | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* A convenience method to avoid a large number of @Test(expected=...) tests | ||
* @param message A String message to describe this assertion | ||
* @param expected An Exception class that the Runnable should throw | ||
* @param runnable A Runnable that is expected to throw the runtime exception | ||
*/ | ||
public static void assertThrows( | ||
String message, Class<? extends Exception> expected, Runnable runnable) { | ||
try { | ||
runnable.run(); | ||
Assert.fail("No exception was thrown (" + message + "), expected: " + | ||
expected.getName()); | ||
} catch (Exception actual) { | ||
try { | ||
Assert.assertEquals(message, expected, actual.getClass()); | ||
} catch (AssertionError e) { | ||
e.addSuppressed(actual); | ||
throw e; | ||
} | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
parquet-common/src/test/java/org/apache/parquet/util/Concatenator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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.parquet.util; | ||
|
||
/** | ||
* This is a class for testing DynMethods and DynConstructors. | ||
*/ | ||
public class Concatenator { | ||
public static class SomeCheckedException extends Exception { | ||
} | ||
|
||
private String sep = ""; | ||
|
||
public Concatenator() { | ||
} | ||
|
||
public Concatenator(String sep) { | ||
this.sep = sep; | ||
} | ||
|
||
private Concatenator(char sep) { | ||
this.sep = String.valueOf(sep); | ||
} | ||
|
||
public Concatenator(Exception e) throws Exception { | ||
throw e; | ||
} | ||
|
||
public static Concatenator newConcatenator(String sep) { | ||
return new Concatenator(sep); | ||
} | ||
|
||
private void setSeparator(String sep) { | ||
this.sep = sep; | ||
} | ||
|
||
public String concat(String left, String right) { | ||
return left + sep + right; | ||
} | ||
|
||
public String concat(String left, String middle, String right) { | ||
return left + sep + middle + sep + right; | ||
} | ||
|
||
public String concat(Exception e) throws Exception { | ||
throw e; | ||
} | ||
|
||
public String concat(String... strings) { | ||
if (strings.length >= 1) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(strings[0]); | ||
for (int i = 1; i < strings.length; i += 1) { | ||
sb.append(sep); | ||
sb.append(strings[i]); | ||
} | ||
return sb.toString(); | ||
} | ||
return null; | ||
} | ||
|
||
public static String cat(String... strings) { | ||
return new Concatenator().concat(strings); | ||
} | ||
} |
Oops, something went wrong.