-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide gRPC api for input tables (#1440)
This pull request is broken into three commits to start (with JS API client code to follow in a later pull request): * ClassUtil improvements * Proposed MutableInputTable api enhancements * Proposed gRPC api and implementation ClassUtil got its lookupClass from the dataobjects ClassUtil, but this implementation isn't thread safe, and while it supports both Class.getName() and Class.getCanonicalName() array notation, it only supports getName() inner type notation. Additionally, it initializes the class on first mention, which could mean for example that an arbitrary doPut could force the server to load a class, even if not serializable. This commit still supports (ignores) generic arguments provided to the class, but otherwise delegates to common-lang3 to actually find the class, and provide the class instance without initializing it. The MutableInputTable changes are intended to make it easier to use from gRPC on the server, and removes some details where the DHE openapi was used to provide implementation details of the input table. The gRPC API adds a createInputTable call in table service (still has some TODOs for discussion), and provides a separate gRPC service to interact with the input table itself. Partial #1271
- Loading branch information
Showing
22 changed files
with
596 additions
and
169 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
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
116 changes: 116 additions & 0 deletions
116
Base/src/test/java/io/deephaven/base/ClassUtilTest.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,116 @@ | ||
package io.deephaven.base; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertSame; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ClassUtilTest { | ||
@Parameterized.Parameters | ||
public static List<Function<Class<?>, String>[]> naming() { | ||
return Arrays.asList( | ||
new Function[] {(Function<Class<?>, String>) Class::getName}, | ||
new Function[] {(Function<Class<?>, String>) Class::getCanonicalName}); | ||
} | ||
|
||
private final Function<Class<?>, String> namer; | ||
|
||
public ClassUtilTest(Function<Class<?>, String> namer) { | ||
this.namer = namer; | ||
} | ||
|
||
private Class<?> lookup(Class<?> clazz) throws ClassNotFoundException { | ||
String string = namer.apply(clazz); | ||
System.out.println(string); | ||
return ClassUtil.lookupClass(string); | ||
} | ||
|
||
private void assertRoundTrip(Class<?> clazz) throws ClassNotFoundException { | ||
assertSame(clazz, lookup(clazz)); | ||
} | ||
|
||
@Test | ||
public void lookupClassSimple() throws ClassNotFoundException { | ||
assertRoundTrip(String.class); | ||
assertRoundTrip(ClassUtilTest.class); | ||
} | ||
|
||
@Test | ||
public void lookupClassPrimitive() throws ClassNotFoundException { | ||
assertRoundTrip(int.class); | ||
assertRoundTrip(Integer.class); | ||
assertRoundTrip(char.class); | ||
|
||
// assertRoundTrip(void.class); | ||
assertRoundTrip(Void.class); | ||
} | ||
|
||
@Test | ||
public void lookupClassArray() throws ClassNotFoundException { | ||
assertRoundTrip(String[].class); | ||
assertRoundTrip(String[][][][][][].class); | ||
assertRoundTrip(ClassUtilTest[][][][][][].class); | ||
|
||
assertRoundTrip(int[].class); | ||
} | ||
|
||
@Test | ||
public void lookupClassInner() throws ClassNotFoundException { | ||
assertRoundTrip(StaticInnerClass.class); | ||
assertRoundTrip(InnerClass.class); | ||
assertRoundTrip(StaticInnerClass.StaticInnerStaticInnerClass.class); | ||
assertRoundTrip(StaticInnerClass.InnerStaticInnerClass.class); | ||
assertRoundTrip(InnerClass.InnerInnerClass.class); | ||
assertRoundTrip(Outer.class); | ||
} | ||
|
||
@Test | ||
public void lookupClassWithClinit() throws ClassNotFoundException { | ||
assertRoundTrip(VerifyNotInitialized.class); | ||
assertFalse(verifyNotInitializedWasNotInitialized); | ||
} | ||
|
||
@Test | ||
public void testGenericStrings() throws ClassNotFoundException { | ||
assertSame(Map.Entry.class, ClassUtil.lookupClass(namer.apply(Map.Entry.class) + "<String, String>")); | ||
// note that this name isn't quite legal for getName(), will try a few iterations to make sure we DWIM | ||
assertSame(Map.Entry[].class, ClassUtil.lookupClass(namer.apply(Map.Entry.class) + "<String, String>[]")); | ||
assertSame(Map.Entry[].class, ClassUtil.lookupClass(namer.apply(Map.Entry[].class) + "<String, String>")); | ||
assertSame(Map.Entry[].class, ClassUtil.lookupClass("[L" + namer.apply(Map.Entry.class) + "<String, String>;")); | ||
} | ||
|
||
public static class StaticInnerClass { | ||
|
||
public class StaticInnerStaticInnerClass { | ||
} | ||
public static class InnerStaticInnerClass { | ||
} | ||
} | ||
|
||
public class InnerClass { | ||
public class InnerInnerClass { | ||
} | ||
} | ||
|
||
// Do not reset this by hand, that won't cause the class to be re-initialized | ||
public static boolean verifyNotInitializedWasNotInitialized = false; | ||
} | ||
|
||
|
||
class Outer { | ||
} | ||
|
||
|
||
class VerifyNotInitialized { | ||
static { | ||
ClassUtilTest.verifyNotInitializedWasNotInitialized = true; | ||
} | ||
} |
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
Oops, something went wrong.