This is an automated email from the ASF dual-hosted git repository. gjacoby pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push: new 6a29349 PHOENIX-6011:ServerCacheClient throw NullPointerException (#836) 6a29349 is described below commit 6a293496ba0bb264964ea9d124bc624c14db32ce Author: wangchao316 <66939405+wangchao...@users.noreply.github.com> AuthorDate: Sun Jul 19 12:52:09 2020 +0800 PHOENIX-6011:ServerCacheClient throw NullPointerException (#836) --- .../apache/phoenix/cache/ServerCacheClient.java | 3 ++ .../phoenix/cache/ServerCacheClientTest.java | 47 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/cache/ServerCacheClient.java b/phoenix-core/src/main/java/org/apache/phoenix/cache/ServerCacheClient.java index d6483b8..600c74b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/cache/ServerCacheClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/cache/ServerCacheClient.java @@ -336,6 +336,9 @@ public class ServerCacheClient { } finally { try { if (!success) { + if (hashCacheSpec != null) { + SQLCloseables.closeAllQuietly(Collections.singletonList(hashCacheSpec)); + } SQLCloseables.closeAllQuietly(Collections.singletonList(hashCacheSpec)); for (Future<Boolean> future : futures) { future.cancel(true); diff --git a/phoenix-core/src/test/java/org/apache/phoenix/cache/ServerCacheClientTest.java b/phoenix-core/src/test/java/org/apache/phoenix/cache/ServerCacheClientTest.java new file mode 100644 index 0000000..496fb1c --- /dev/null +++ b/phoenix-core/src/test/java/org/apache/phoenix/cache/ServerCacheClientTest.java @@ -0,0 +1,47 @@ +/* + * 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. + */ +package org.apache.phoenix.cache; + +import static org.junit.Assert.assertEquals; + +import java.sql.SQLException; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.query.ConnectionQueryServices; +import org.apache.phoenix.schema.PNameFactory; +import org.apache.phoenix.schema.PTableImpl; +import org.junit.Test; +import org.mockito.Mockito; + +public class ServerCacheClientTest { + @Test + public void testAddServerCache() throws SQLException { + PhoenixConnection connection = Mockito.mock(PhoenixConnection.class); + ConnectionQueryServices services = Mockito.mock(ConnectionQueryServices.class); + Mockito.when(services.getExecutor()).thenReturn(null); + Mockito.when(connection.getQueryServices()).thenReturn(services); + byte[] tableName = Bytes.toBytes("TableName"); + PTableImpl pTable = Mockito.mock(PTableImpl.class); + Mockito.when(pTable.getPhysicalName()).thenReturn(PNameFactory.newName("TableName")); + Mockito.when(services.getAllTableRegions(tableName)).thenThrow(new SQLException("Test Exception")); + ServerCacheClient client = new ServerCacheClient(connection); + try { + client.addServerCache(null, null, null, null, pTable, false); + } catch (Exception e) { + assertEquals(e.getMessage(), "Test Exception"); + } + } +}