use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ZKAuthenticatorTest method testUserAuthentication.
@Test
public void testUserAuthentication() throws Exception {
// testing the usecase when trying to authenticate with the new hash type
String principal = "myTestUser";
byte[] rawPass = "myPassword".getBytes(UTF_8);
// creating hash with up to date algorithm
byte[] newHash = ZKSecurityTool.createPass(rawPass.clone());
// mocking zk interaction
ServerContext context = MockServerContext.getWithZK(InstanceId.of("example"), "", 30_000);
ZooReaderWriter zr = createMock(ZooReaderWriter.class);
expect(context.getZooReaderWriter()).andReturn(zr).anyTimes();
ZooKeeper zk = createMock(ZooKeeper.class);
expect(zk.getChildren(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Arrays.asList(principal)).anyTimes();
expect(zk.exists(EasyMock.matches("/accumulo/example/users/" + principal), EasyMock.anyObject(Watcher.class))).andReturn(new Stat()).anyTimes();
expect(zr.getZooKeeper()).andReturn(zk).anyTimes();
expect(zk.getData(EasyMock.matches("/accumulo/example/users/" + principal), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(newHash).once();
replay(context, zr, zk);
// creating authenticator
ZKAuthenticator auth = new ZKAuthenticator();
auth.initialize(context);
PasswordToken token = new PasswordToken(rawPass.clone());
// verifying that if the new type of hash is stored in zk authentication works as expected
assertTrue(auth.authenticateUser(principal, token));
verify(context, zr, zk);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class BaseHostRegexTableLoadBalancerTest method createMockContext.
protected ServerContext createMockContext() {
ServerContext mockContext = EasyMock.createMock(ServerContext.class);
expect(mockContext.getProperties()).andReturn(new Properties()).anyTimes();
expect(mockContext.getZooKeepers()).andReturn("").anyTimes();
expect(mockContext.getInstanceName()).andReturn("test").anyTimes();
expect(mockContext.getZooKeepersSessionTimeOut()).andReturn(30).anyTimes();
expect(mockContext.getInstanceID()).andReturn(InstanceId.of("1111")).anyTimes();
expect(mockContext.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/1111").anyTimes();
return mockContext;
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testSplitCurrentByRegexUsingOverlappingPools.
@Test
public void testSplitCurrentByRegexUsingOverlappingPools() {
ServerContext context = createMockContext();
replay(context);
initFactory(new TestServerConfigurationFactory(context) {
@Override
public synchronized AccumuloConfiguration getSystemConfiguration() {
HashMap<String, String> props = new HashMap<>(DEFAULT_TABLE_PROPERTIES);
props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + FOO.getTableName(), "r.*");
props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*|r02.*");
return new ConfigurationCopy(props);
}
});
Map<String, SortedMap<TServerInstance, TabletServerStatus>> groups = this.splitCurrentByRegex(createCurrent(15));
// Groups foo, bar, and the default pool which contains all known hosts
assertEquals(3, groups.size());
assertTrue(groups.containsKey(FOO.getTableName()));
assertTrue(groups.containsKey(DEFAULT_POOL));
for (String pool : new String[] { FOO.getTableName(), DEFAULT_POOL }) {
SortedMap<TServerInstance, TabletServerStatus> fooHosts = groups.get(pool);
assertEquals(15, fooHosts.size());
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.11:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.12:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.13:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.14:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.15:9997", 1)));
}
assertTrue(groups.containsKey(BAR.getTableName()));
SortedMap<TServerInstance, TabletServerStatus> barHosts = groups.get(BAR.getTableName());
assertEquals(10, barHosts.size());
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1)));
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method initFactory.
private void initFactory(ServerConfigurationFactory factory) {
ServerContext context = createMockContext();
expect(context.getConfiguration()).andReturn(factory.getSystemConfiguration()).anyTimes();
expect(context.getTableConfiguration(FOO.getId())).andReturn(factory.getTableConfiguration(FOO.getId())).anyTimes();
expect(context.getTableConfiguration(BAR.getId())).andReturn(factory.getTableConfiguration(BAR.getId())).anyTimes();
expect(context.getTableConfiguration(BAZ.getId())).andReturn(factory.getTableConfiguration(BAZ.getId())).anyTimes();
replay(context);
init(context);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testSplitCurrentByRegexUsingIP.
@Test
public void testSplitCurrentByRegexUsingIP() {
ServerContext context = createMockContext();
replay(context);
initFactory(new TestServerConfigurationFactory(context) {
@Override
public synchronized AccumuloConfiguration getSystemConfiguration() {
HashMap<String, String> props = new HashMap<>();
props.put(HostRegexTableLoadBalancer.HOST_BALANCER_OOB_CHECK_KEY, "30s");
props.put(HostRegexTableLoadBalancer.HOST_BALANCER_REGEX_USING_IPS_KEY, "true");
props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + FOO.getTableName(), "192\\.168\\.0\\.[1-5]");
props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "192\\.168\\.0\\.[6-9]|192\\.168\\.0\\.10");
return new ConfigurationCopy(props);
}
});
assertTrue(isIpBasedRegex());
Map<String, SortedMap<TServerInstance, TabletServerStatus>> groups = this.splitCurrentByRegex(createCurrent(15));
assertEquals(3, groups.size());
assertTrue(groups.containsKey(FOO.getTableName()));
SortedMap<TServerInstance, TabletServerStatus> fooHosts = groups.get(FOO.getTableName());
assertEquals(5, fooHosts.size());
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1)));
assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1)));
assertTrue(groups.containsKey(BAR.getTableName()));
SortedMap<TServerInstance, TabletServerStatus> barHosts = groups.get(BAR.getTableName());
assertEquals(5, barHosts.size());
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1)));
assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1)));
assertTrue(groups.containsKey(DEFAULT_POOL));
SortedMap<TServerInstance, TabletServerStatus> defHosts = groups.get(DEFAULT_POOL);
assertEquals(5, defHosts.size());
assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.11:9997", 1)));
assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.12:9997", 1)));
assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.13:9997", 1)));
assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.14:9997", 1)));
assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.15:9997", 1)));
}
Aggregations