use of org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry 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'", default_binary_name);
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
return true;
}
}).doAnswer(new Answer() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
boolean result = (boolean) invocation.callRealMethod();
assertFalse("syncWithRemoteRegistry() should return false", result);
return false;
}
}).when(functionImplementationRegistry).syncWithRemoteRegistry(anyLong());
test("select custom_lower('A') from (values(1))");
try {
test("select unknown_lower('A') from (values(1))");
} catch (UserRemoteException e) {
assertThat(e.getMessage(), containsString("No match found for function signature unknown_lower(<CHARACTER>)"));
}
verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong());
LocalFunctionRegistry localFunctionRegistry = Deencapsulation.getField(functionImplementationRegistry, "localFunctionRegistry");
assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion());
}
use of org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry in project drill by axbaretto.
the class TestDynamicUDFSupport method testLazyInitNoReload.
@Test
public void testLazyInitNoReload() throws Exception {
FunctionImplementationRegistry functionImplementationRegistry = spyFunctionImplementationRegistry();
copyDefaultJarsToStagingArea();
test("create function using jar '%s'", default_binary_name);
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
return true;
}
}).doAnswer(new Answer() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
boolean result = (boolean) invocation.callRealMethod();
assertFalse("syncWithRemoteRegistry() should return false", result);
return false;
}
}).when(functionImplementationRegistry).syncWithRemoteRegistry(anyLong());
test("select custom_lower('A') from (values(1))");
try {
test("select unknown_lower('A') from (values(1))");
} catch (UserRemoteException e) {
assertThat(e.getMessage(), containsString("No match found for function signature unknown_lower(<CHARACTER>)"));
}
verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong());
LocalFunctionRegistry localFunctionRegistry = (LocalFunctionRegistry) FieldUtils.readField(functionImplementationRegistry, "localFunctionRegistry", true);
assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion());
}
use of org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry 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.expr.fn.registry.LocalFunctionRegistry in project drill by apache.
the class TestDynamicUDFSupport method testLazyInitConcurrent.
@Test
public void testLazyInitConcurrent() throws Exception {
FunctionImplementationRegistry functionImplementationRegistry = spyFunctionImplementationRegistry();
copyDefaultJarsToStagingArea();
test("create function using jar '%s'", default_binary_name);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final String query = "select custom_lower('A') from (values(1))";
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
latch1.await();
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
latch2.countDown();
return true;
}
}).doAnswer(new Answer() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
latch1.countDown();
latch2.await();
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
return true;
}
}).when(functionImplementationRegistry).syncWithRemoteRegistry(anyLong());
SimpleQueryRunner simpleQueryRunner = new SimpleQueryRunner(query);
Thread thread1 = new Thread(simpleQueryRunner);
Thread thread2 = new Thread(simpleQueryRunner);
thread1.start();
thread2.start();
thread1.join();
thread2.join();
verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong());
LocalFunctionRegistry localFunctionRegistry = Deencapsulation.getField(functionImplementationRegistry, "localFunctionRegistry");
assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion());
}
use of org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry in project drill by axbaretto.
the class TestDynamicUDFSupport method testLazyInitConcurrent.
@Test
public void testLazyInitConcurrent() throws Exception {
FunctionImplementationRegistry functionImplementationRegistry = spyFunctionImplementationRegistry();
copyDefaultJarsToStagingArea();
test("create function using jar '%s'", default_binary_name);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final String query = "select custom_lower('A') from (values(1))";
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
latch1.await();
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
latch2.countDown();
return true;
}
}).doAnswer(new Answer() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
latch1.countDown();
latch2.await();
boolean result = (boolean) invocation.callRealMethod();
assertTrue("syncWithRemoteRegistry() should return true", result);
return true;
}
}).when(functionImplementationRegistry).syncWithRemoteRegistry(anyLong());
SimpleQueryRunner simpleQueryRunner = new SimpleQueryRunner(query);
Thread thread1 = new Thread(simpleQueryRunner);
Thread thread2 = new Thread(simpleQueryRunner);
thread1.start();
thread2.start();
thread1.join();
thread2.join();
verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong());
LocalFunctionRegistry localFunctionRegistry = (LocalFunctionRegistry) FieldUtils.readField(functionImplementationRegistry, "localFunctionRegistry", true);
assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion());
}
Aggregations