use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ReplicationProcessorTest method peerTypeExtractionFromConfiguration.
@Test
public void peerTypeExtractionFromConfiguration() {
ServerContext context = createMock(ServerContext.class);
String peerName = "peer";
String configuration = "java.lang.String,foo";
var conf = new ConfigurationCopy(Map.of(Property.REPLICATION_PEERS + peerName, configuration));
expect(context.getConfiguration()).andReturn(conf);
replay(context);
ReplicationProcessor proc = new ReplicationProcessor(context);
assertEquals(configuration, proc.getPeerType(peerName));
verify(context);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class InMemoryMapTest method getServerContext.
public static ServerContext getServerContext() {
Configuration hadoopConf = new Configuration();
ServerContext context = EasyMock.createMock(ServerContext.class);
EasyMock.expect(context.getCryptoService()).andReturn(CryptoServiceFactory.newDefaultInstance()).anyTimes();
EasyMock.expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes();
EasyMock.expect(context.getHadoopConf()).andReturn(hadoopConf).anyTimes();
EasyMock.replay(context);
return context;
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class CloseWriteAheadLogReferencesIT method setupEasyMockStuff.
@Before
public void setupEasyMockStuff() {
SiteConfiguration siteConfig = EasyMock.createMock(SiteConfiguration.class);
final AccumuloConfiguration systemConf = new ConfigurationCopy(new HashMap<>());
// Just make the SiteConfiguration delegate to our AccumuloConfiguration
// Presently, we only need get(Property) and iterator().
EasyMock.expect(siteConfig.get(EasyMock.anyObject(Property.class))).andAnswer(() -> {
Object[] args = EasyMock.getCurrentArguments();
return systemConf.get((Property) args[0]);
}).anyTimes();
EasyMock.expect(siteConfig.getBoolean(EasyMock.anyObject(Property.class))).andAnswer(() -> {
Object[] args = EasyMock.getCurrentArguments();
return systemConf.getBoolean((Property) args[0]);
}).anyTimes();
EasyMock.expect(siteConfig.iterator()).andAnswer(systemConf::iterator).anyTimes();
ServerContext context = createMock(ServerContext.class);
expect(context.getProperties()).andReturn(new Properties()).anyTimes();
expect(context.getZooKeepers()).andReturn("localhost").anyTimes();
expect(context.getInstanceName()).andReturn("test").anyTimes();
expect(context.getZooKeepersSessionTimeOut()).andReturn(30000).anyTimes();
expect(context.getInstanceID()).andReturn(InstanceId.of("1111")).anyTimes();
expect(context.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/1111").anyTimes();
replay(siteConfig, context);
refs = new WrappedCloseWriteAheadLogReferences(context);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ZombieTServer method main.
public static void main(String[] args) throws Exception {
int port = random.nextInt(30000) + 2000;
var context = new ServerContext(SiteConfiguration.auto());
TransactionWatcher watcher = new TransactionWatcher(context);
final ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
Processor<Iface> processor = new Processor<>(tch);
ServerAddress serverPort = TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "ZombieTServer", "walking dead", 2, ThreadPools.DEFAULT_TIMEOUT_MILLISECS, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", port));
String addressString = serverPort.address.toString();
var zLockPath = ServiceLock.path(context.getZooKeeperRoot() + Constants.ZTSERVERS + "/" + addressString);
ZooReaderWriter zoo = context.getZooReaderWriter();
zoo.putPersistentData(zLockPath.toString(), new byte[] {}, NodeExistsPolicy.SKIP);
ServiceLock zlock = new ServiceLock(zoo.getZooKeeper(), zLockPath, UUID.randomUUID());
LockWatcher lw = new LockWatcher() {
@SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit() is a bad idea here, but okay for now, since it's a test")
@Override
public void lostLock(final LockLossReason reason) {
try {
tch.halt(TraceUtil.traceInfo(), null, null);
} catch (Exception ex) {
log.error("Exception", ex);
System.exit(1);
}
}
@SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit() is a bad idea here, but okay for now, since it's a test")
@Override
public void unableToMonitorLockNode(Exception e) {
try {
tch.halt(TraceUtil.traceInfo(), null, null);
} catch (Exception ex) {
log.error("Exception", ex);
System.exit(1);
}
}
};
byte[] lockContent = new ServerServices(addressString, Service.TSERV_CLIENT).toString().getBytes(UTF_8);
if (zlock.tryLock(lw, lockContent)) {
log.debug("Obtained tablet server lock {}", zlock.getLockPath());
}
// modify metadata
synchronized (tch) {
while (!tch.halted) {
tch.wait();
}
}
System.exit(0);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class WALSunnyDayIT method test.
@Test
public void test() throws Exception {
MiniAccumuloClusterImpl mac = getCluster();
MiniAccumuloClusterControl control = mac.getClusterControl();
control.stop(GARBAGE_COLLECTOR);
ServerContext context = getServerContext();
try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
String tableName = getUniqueNames(1)[0];
c.tableOperations().create(tableName);
writeSomeData(c, tableName, 1, 1);
// wal markers are added lazily
Map<String, WalState> wals = getWALsAndAssertCount(context, 2);
assertEquals("all WALs should be in use", 2, countInUse(wals.values()));
// roll log, get a new next
writeSomeData(c, tableName, 1001, 50);
Map<String, WalState> walsAfterRoll = getWALsAndAssertCount(context, 3);
assertTrue("new WALs should be a superset of the old WALs", walsAfterRoll.keySet().containsAll(wals.keySet()));
assertEquals("all WALs should be in use", 3, countInUse(walsAfterRoll.values()));
// flush the tables
for (String table : new String[] { tableName, MetadataTable.NAME, RootTable.NAME }) {
c.tableOperations().flush(table, null, null, true);
}
sleepUninterruptibly(1, TimeUnit.SECONDS);
// rolled WAL is no longer in use, but needs to be GC'd
Map<String, WalState> walsAfterflush = getWALsAndAssertCount(context, 3);
assertEquals("inUse should be 2", 2, countInUse(walsAfterflush.values()));
// let the GC run for a little bit
control.start(GARBAGE_COLLECTOR);
sleepUninterruptibly(5, TimeUnit.SECONDS);
// make sure the unused WAL goes away
getWALsAndAssertCount(context, 2);
control.stop(GARBAGE_COLLECTOR);
// restart the tserver, but don't run recovery on all tablets
control.stop(TABLET_SERVER);
// this delays recovery on the normal tables
assertEquals(0, cluster.exec(SetGoalState.class, "SAFE_MODE").getProcess().waitFor());
control.start(TABLET_SERVER);
// wait for the metadata table to go back online
getRecoveryMarkers(c);
// allow a little time for the manager to notice ASSIGNED_TO_DEAD_SERVER tablets
sleepUninterruptibly(5, TimeUnit.SECONDS);
Map<KeyExtent, List<String>> markers = getRecoveryMarkers(c);
// log.debug("markers " + markers);
assertEquals("one tablet should have markers", 1, markers.size());
assertEquals("tableId of the keyExtent should be 1", "1", markers.keySet().iterator().next().tableId().canonical());
// put some data in the WAL
assertEquals(0, cluster.exec(SetGoalState.class, "NORMAL").getProcess().waitFor());
verifySomeData(c, tableName, 1001 * 50 + 1);
writeSomeData(c, tableName, 100, 100);
Map<String, WalState> walsAfterRestart = getWALsAndAssertCount(context, 4);
// log.debug("wals after " + walsAfterRestart);
assertEquals("used WALs after restart should be 4", 4, countInUse(walsAfterRestart.values()));
control.start(GARBAGE_COLLECTOR);
sleepUninterruptibly(5, TimeUnit.SECONDS);
Map<String, WalState> walsAfterRestartAndGC = getWALsAndAssertCount(context, 2);
assertEquals("logs in use should be 2", 2, countInUse(walsAfterRestartAndGC.values()));
}
}
Aggregations