forked from apache/accumulo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.1' into 3.1, fix test, remove unused var
- Loading branch information
Showing
6 changed files
with
121 additions
and
20 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
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
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
102 changes: 102 additions & 0 deletions
102
server/base/src/test/java/org/apache/accumulo/server/util/PropUtilTest.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,102 @@ | ||
/* | ||
* 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 | ||
* | ||
* https://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. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.accumulo.server.util; | ||
|
||
import static org.easymock.EasyMock.createMock; | ||
import static org.easymock.EasyMock.expect; | ||
import static org.easymock.EasyMock.replay; | ||
import static org.easymock.EasyMock.verify; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.accumulo.core.classloader.ClassLoaderUtil; | ||
import org.apache.accumulo.core.conf.AccumuloConfiguration; | ||
import org.apache.accumulo.core.conf.Property; | ||
import org.apache.accumulo.core.data.InstanceId; | ||
import org.apache.accumulo.core.data.TableId; | ||
import org.apache.accumulo.core.spi.common.ContextClassLoaderFactory; | ||
import org.apache.accumulo.server.ServerContext; | ||
import org.apache.accumulo.server.conf.store.TablePropKey; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PropUtilTest { | ||
|
||
private static final String TEST_CONTEXT_NAME = "TestContext"; | ||
private static final String INVALID_TEST_CONTEXT_NAME = "InvalidTestContext"; | ||
|
||
public static class TestContextClassLoaderFactory implements ContextClassLoaderFactory { | ||
|
||
@Override | ||
public ClassLoader getClassLoader(String contextName) { | ||
if (contextName.equals(TEST_CONTEXT_NAME)) { | ||
return this.getClass().getClassLoader(); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
|
||
@BeforeEach | ||
public void before() { | ||
ClassLoaderUtil.resetContextFactoryForTests(); | ||
} | ||
|
||
@Test | ||
public void testSetClasspathContextFails() { | ||
ServerContext ctx = createMock(ServerContext.class); | ||
AccumuloConfiguration conf = createMock(AccumuloConfiguration.class); | ||
InstanceId iid = createMock(InstanceId.class); | ||
TableId tid = createMock(TableId.class); | ||
TablePropKey tkey = TablePropKey.of(iid, tid); | ||
|
||
expect(ctx.getConfiguration()).andReturn(conf).once(); | ||
expect(conf.get(Property.GENERAL_CONTEXT_CLASSLOADER_FACTORY)) | ||
.andReturn(TestContextClassLoaderFactory.class.getName()); | ||
|
||
replay(ctx, conf, iid, tid); | ||
IllegalArgumentException e = | ||
assertThrows(IllegalArgumentException.class, () -> PropUtil.validateProperties(ctx, tkey, | ||
Map.of(Property.TABLE_CLASSLOADER_CONTEXT.getKey(), INVALID_TEST_CONTEXT_NAME))); | ||
assertEquals("Unable to resolve classloader for context: " + INVALID_TEST_CONTEXT_NAME, | ||
e.getMessage()); | ||
verify(ctx, conf, iid, tid); | ||
} | ||
|
||
@Test | ||
public void testSetClasspathContext() { | ||
ServerContext ctx = createMock(ServerContext.class); | ||
AccumuloConfiguration conf = createMock(AccumuloConfiguration.class); | ||
InstanceId iid = createMock(InstanceId.class); | ||
TableId tid = createMock(TableId.class); | ||
TablePropKey tkey = TablePropKey.of(iid, tid); | ||
|
||
expect(ctx.getConfiguration()).andReturn(conf).once(); | ||
expect(conf.get(Property.GENERAL_CONTEXT_CLASSLOADER_FACTORY)) | ||
.andReturn(TestContextClassLoaderFactory.class.getName()); | ||
|
||
replay(ctx, conf, iid, tid); | ||
PropUtil.validateProperties(ctx, tkey, | ||
Map.of(Property.TABLE_CLASSLOADER_CONTEXT.getKey(), TEST_CONTEXT_NAME)); | ||
verify(ctx, conf, iid, tid); | ||
} | ||
|
||
} |