Search in sources :

Example 1 with LocalFunctionRegistry

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());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) Test(org.junit.Test)

Example 2 with LocalFunctionRegistry

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());
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) SlowTest(org.apache.drill.categories.SlowTest) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) Test(org.junit.Test)

Example 3 with LocalFunctionRegistry

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());
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Mockito.doThrow(org.mockito.Mockito.doThrow) TestBuilder(org.apache.drill.test.TestBuilder) SlowTest(org.apache.drill.categories.SlowTest) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) HadoopUtils.hadoopToJavaPath(org.apache.drill.test.HadoopUtils.hadoopToJavaPath) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Path(java.nio.file.Path) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ConfigConstants(org.apache.drill.common.config.ConfigConstants) Category(org.junit.experimental.categories.Category) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) Assert.assertFalse(org.junit.Assert.assertFalse) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeClass(org.junit.BeforeClass) BaseTestQuery(org.apache.drill.test.BaseTestQuery) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Mockito.spy(org.mockito.Mockito.spy) DrillbitContext(org.apache.drill.exec.server.DrillbitContext) RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ExpectedException(org.junit.rules.ExpectedException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Registry(org.apache.drill.exec.proto.UserBitShared.Registry) Lists(org.apache.drill.shaded.guava.com.google.common.collect.Lists) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Jar(org.apache.drill.exec.proto.UserBitShared.Jar) JarUtil(org.apache.drill.exec.util.JarUtil) Mockito.reset(org.mockito.Mockito.reset) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) SlowTest(org.apache.drill.categories.SlowTest) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) Test(org.junit.Test)

Example 4 with LocalFunctionRegistry

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());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) Test(org.junit.Test)

Example 5 with LocalFunctionRegistry

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());
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) SlowTest(org.apache.drill.categories.SlowTest) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) Test(org.junit.Test)

Aggregations

FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)6 LocalFunctionRegistry (org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry)6 Test (org.junit.Test)6 Mockito.doAnswer (org.mockito.Mockito.doAnswer)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 SlowTest (org.apache.drill.categories.SlowTest)4 SqlFunctionTest (org.apache.drill.categories.SqlFunctionTest)4 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 List (java.util.List)2 FileUtils (org.apache.commons.io.FileUtils)2 ArrayUtils (org.apache.commons.lang3.ArrayUtils)2 FieldUtils (org.apache.commons.lang3.reflect.FieldUtils)2