use of org.apache.drill.exec.proto.UserBitShared.Registry in project drill by axbaretto.
the class TestDynamicUDFSupport method testExceedRetryAttemptsDuringUnregistration.
@Test
public void testExceedRetryAttemptsDuringUnregistration() throws Exception {
final RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
final Path registryPath = hadoopToJavaPath(remoteFunctionRegistry.getRegistryArea());
copyDefaultJarsToStagingArea();
test("create function using jar '%s'", default_binary_name);
reset(remoteFunctionRegistry);
doThrow(new VersionMismatchException("Version mismatch detected", 1)).when(remoteFunctionRegistry).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
String summary = "Failed to update remote function registry. Exceeded retry attempts limit.";
testBuilder().sqlQuery("drop function using jar '%s'", default_binary_name).unOrdered().baselineColumns("ok", "summary").baselineValues(false, summary).go();
verify(remoteFunctionRegistry, times(remoteFunctionRegistry.getRetryAttempts() + 1)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
assertTrue("Binary should be present in registry area", registryPath.resolve(default_binary_name).toFile().exists());
assertTrue("Source should be present in registry area", registryPath.resolve(default_source_name).toFile().exists());
Registry registry = remoteFunctionRegistry.getRegistry(new DataChangeVersion());
assertEquals("Registry should contain one jar", registry.getJarList().size(), 1);
assertEquals(registry.getJar(0).getName(), default_binary_name);
}
use of org.apache.drill.exec.proto.UserBitShared.Registry in project drill by axbaretto.
the class TestDynamicUDFSupport method testConcurrentRemoteRegistryUpdateForDifferentJars.
@Test
public void testConcurrentRemoteRegistryUpdateForDifferentJars() throws Exception {
RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
latch2.countDown();
latch1.await();
invocation.callRealMethod();
return null;
}
}).when(remoteFunctionRegistry).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
final String jarName1 = default_binary_name;
final String jarName2 = "DrillUDF-2.0.jar";
final String query = "create function using jar '%s'";
copyDefaultJarsToStagingArea();
copyJarsToStagingArea(jarName2, JarUtil.getSourceName(jarName2));
Thread thread1 = new Thread(new TestBuilderRunner(testBuilder().sqlQuery(query, jarName1).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("The following UDFs in jar %s have been registered:\n" + "[custom_lower(VARCHAR-REQUIRED)]", jarName1))));
Thread thread2 = new Thread(new TestBuilderRunner(testBuilder().sqlQuery(query, jarName2).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("The following UDFs in jar %s have been registered:\n" + "[custom_upper(VARCHAR-REQUIRED)]", jarName2))));
thread1.start();
thread2.start();
latch2.await();
latch1.countDown();
thread1.join();
thread2.join();
DataChangeVersion version = new DataChangeVersion();
Registry registry = remoteFunctionRegistry.getRegistry(version);
assertEquals("Remote registry version should match", 2, version.getVersion());
List<Jar> actualJars = registry.getJarList();
List<String> expectedJars = Lists.newArrayList(jarName1, jarName2);
assertEquals("Only one jar should be registered", 2, actualJars.size());
for (Jar jar : actualJars) {
assertTrue("Jar should be present in remote function registry", expectedJars.contains(jar.getName()));
}
verify(remoteFunctionRegistry, times(3)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
}
use of org.apache.drill.exec.proto.UserBitShared.Registry in project drill by apache.
the class TestDynamicUDFSupport method testConcurrentRemoteRegistryUpdateWithDuplicates.
@Test
public void testConcurrentRemoteRegistryUpdateWithDuplicates() throws Exception {
RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final CountDownLatch latch3 = new CountDownLatch(1);
doAnswer(invocation -> {
latch3.countDown();
latch1.await();
invocation.callRealMethod();
latch2.countDown();
return null;
}).doAnswer(invocation -> {
latch1.countDown();
latch2.await();
invocation.callRealMethod();
return null;
}).when(remoteFunctionRegistry).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
final String jar1 = defaultBinaryJar;
copyDefaultJarsToStagingArea();
final String copyJarName = "drill-custom-lower-copy";
final String jar2 = buildAndCopyJarsToStagingArea(copyJarName, "**/CustomLowerFunction.java", null);
final String query = "create function using jar '%s'";
Thread thread1 = new Thread(new TestBuilderRunner(testBuilder().sqlQuery(query, jar1).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("The following UDFs in jar %s have been registered:\n" + "[custom_lower(VARCHAR-REQUIRED)]", jar1))));
Thread thread2 = new Thread(new TestBuilderRunner(testBuilder().sqlQuery(query, jar2).unOrdered().baselineColumns("ok", "summary").baselineValues(false, String.format("Found duplicated function in %s: custom_lower(VARCHAR-REQUIRED)", jar1))));
thread1.start();
latch3.await();
thread2.start();
thread1.join();
thread2.join();
DataChangeVersion version = new DataChangeVersion();
Registry registry = remoteFunctionRegistry.getRegistry(version);
assertEquals("Remote registry version should match", 2, version.getVersion());
List<Jar> jarList = registry.getJarList();
assertEquals("Only one jar should be registered", 1, jarList.size());
assertEquals("Jar name should match", jar1, jarList.get(0).getName());
verify(remoteFunctionRegistry, times(2)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
}
use of org.apache.drill.exec.proto.UserBitShared.Registry in project drill by apache.
the class TestDynamicUDFSupport method testLazyInitNoReload.
@Test
public void testLazyInitNoReload() throws Exception {
FunctionImplementationRegistry functionImplementationRegistry = spyFunctionImplementationRegistry();
copyDefaultJarsToStagingArea();
test("create function using jar '%s'", defaultBinaryJar);
doAnswer(invocation -> {
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
return true;
}).doAnswer(invocation -> {
boolean result = (boolean) invocation.callRealMethod();
assertFalse("syncWithRemoteRegistry() should return false", result);
return false;
}).when(functionImplementationRegistry).syncWithRemoteRegistry(anyInt());
test("select custom_lower('A') from (values(1))");
try {
test("select unknown_lower('A') from (values(1))");
fail();
} catch (UserRemoteException e) {
assertThat(e.getMessage(), containsString("No match found for function signature unknown_lower(<CHARACTER>)"));
}
verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyInt());
LocalFunctionRegistry localFunctionRegistry = (LocalFunctionRegistry) FieldUtils.readField(functionImplementationRegistry, "localFunctionRegistry", true);
assertEquals("Sync function registry version should match", 2, localFunctionRegistry.getVersion());
}
use of org.apache.drill.exec.proto.UserBitShared.Registry in project drill by apache.
the class TestDynamicUDFSupport method testConcurrentRemoteRegistryUpdateForDifferentJars.
@Test
public void testConcurrentRemoteRegistryUpdateForDifferentJars() throws Exception {
RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
doAnswer(invocation -> {
latch2.countDown();
latch1.await();
invocation.callRealMethod();
return null;
}).when(remoteFunctionRegistry).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
final String jar1 = defaultBinaryJar;
copyDefaultJarsToStagingArea();
final String upperJarName = "drill-custom-upper";
final String jar2 = buildAndCopyJarsToStagingArea(upperJarName, "**/CustomUpperFunction.java", null);
final String query = "create function using jar '%s'";
Thread thread1 = new Thread(new TestBuilderRunner(testBuilder().sqlQuery(query, jar1).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("The following UDFs in jar %s have been registered:\n" + "[custom_lower(VARCHAR-REQUIRED)]", jar1))));
Thread thread2 = new Thread(new TestBuilderRunner(testBuilder().sqlQuery(query, jar2).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("The following UDFs in jar %s have been registered:\n" + "[custom_upper(VARCHAR-REQUIRED)]", jar2))));
thread1.start();
thread2.start();
latch2.await();
latch1.countDown();
thread1.join();
thread2.join();
DataChangeVersion version = new DataChangeVersion();
Registry registry = remoteFunctionRegistry.getRegistry(version);
assertEquals("Remote registry version should match", 3, version.getVersion());
List<Jar> actualJars = registry.getJarList();
List<String> expectedJars = Lists.newArrayList(jar1, jar2);
assertEquals("Only one jar should be registered", 2, actualJars.size());
for (Jar jar : actualJars) {
assertTrue("Jar should be present in remote function registry", expectedJars.contains(jar.getName()));
}
verify(remoteFunctionRegistry, times(3)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
}
Aggregations