Refine search
@Test public void testCurrentTimeInMillis() { EnvironmentEdge mock = mock(EnvironmentEdge.class); EnvironmentEdgeManager.injectEdge(mock); long expectation = 3456; when(mock.currentTime()).thenReturn(expectation); long result = EnvironmentEdgeManager.currentTime(); verify(mock).currentTime(); assertEquals(expectation, result); } }
/** * Test recover lease eventually succeeding. */ @Test public void testRecoverLease() throws IOException { HTU.getConfiguration().setInt("hbase.lease.recovery.dfs.timeout", 1000); CancelableProgressable reporter = Mockito.mock(CancelableProgressable.class); Mockito.when(reporter.progress()).thenReturn(true); DistributedFileSystem dfs = Mockito.mock(DistributedFileSystem.class); // Fail four times and pass on the fifth. Mockito.when(dfs.recoverLease(FILE)). thenReturn(false).thenReturn(false).thenReturn(false).thenReturn(false).thenReturn(true); assertTrue(this.fsHDFSUtils.recoverDFSFileLease(dfs, FILE, HTU.getConfiguration(), reporter)); Mockito.verify(dfs, Mockito.times(5)).recoverLease(FILE); // Make sure we waited at least hbase.lease.recovery.dfs.timeout * 3 (the first two // invocations will happen pretty fast... the we fall into the longer wait loop). assertTrue((EnvironmentEdgeManager.currentTime() - this.startTime) > (3 * HTU.getConfiguration().getInt("hbase.lease.recovery.dfs.timeout", 61000))); }
@Test public void testWarnStuckTasks() throws Exception { final int INTERVAL = 1000; Configuration conf = new Configuration(); conf.setLong(TaskMonitor.RPC_WARN_TIME_KEY, INTERVAL); conf.setLong(TaskMonitor.MONITOR_INTERVAL_KEY, INTERVAL); final TaskMonitor tm = new TaskMonitor(conf); MonitoredRPCHandler t = tm.createRPCStatus("test task"); long then = EnvironmentEdgeManager.currentTime(); t.setRPC("testMethod", new Object[0], then); Thread.sleep(INTERVAL * 2); assertTrue("We did not warn", t.getWarnTime() > then); tm.shutdown(); }
@Test public void testMatchWhenFilterReturnsIncludeAndSeekNextRow() throws IOException { List<MatchCode> expected = new ArrayList<>(); expected.add(ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_ROW); expected.add(ScanQueryMatcher.MatchCode.DONE); Scan scanWithFilter = new Scan(scan).setFilter(new AlwaysIncludeAndSeekNextRowFilter()); long now = EnvironmentEdgeManager.currentTime(); // scan with column 2,4,5 UserScanQueryMatcher qm = UserScanQueryMatcher.create( scanWithFilter, new ScanInfo(this.conf, fam2, 0, 1, ttl, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, rowComparator, false), get.getFamilyMap().get(fam2), now - ttl, now, null); List<KeyValue> memstore = new ArrayList<>(); // ColumnTracker will return INCLUDE_AND_SEEK_NEXT_COL , and filter will return // INCLUDE_AND_SEEK_NEXT_ROW, so final match code will be INCLUDE_AND_SEEK_NEXT_ROW. memstore.add(new KeyValue(row1, fam2, col2, 1, data)); memstore.add(new KeyValue(row2, fam1, col1, data)); List<ScanQueryMatcher.MatchCode> actual = new ArrayList<>(memstore.size()); KeyValue k = memstore.get(0); qm.setToNewRow(k); for (KeyValue kv : memstore) { actual.add(qm.match(kv)); } assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { LOG.debug("expected " + expected.get(i) + ", actual " + actual.get(i)); assertEquals(expected.get(i), actual.get(i)); } }
@Test public void testAbortTimeout() { final int PROC_TIMEOUT_MSEC = 2500; List<String> state = new ArrayList<>(); Procedure<Void> proc = new TestWaitingProcedure("wproc", state, false); proc.setTimeout(PROC_TIMEOUT_MSEC); long startTime = EnvironmentEdgeManager.currentTime(); long rootId = ProcedureTestingUtility.submitAndWait(procExecutor, proc); long execTime = EnvironmentEdgeManager.currentTime() - startTime; LOG.info(Objects.toString(state)); assertTrue("we didn't wait enough execTime=" + execTime, execTime >= PROC_TIMEOUT_MSEC); Procedure<?> result = procExecutor.getResult(rootId); assertTrue(state.toString(), result.isFailed()); ProcedureTestingUtility.assertIsTimeoutException(result); assertEquals(state.toString(), 2, state.size()); assertEquals("wproc-execute", state.get(0)); assertEquals("wproc-rollback", state.get(1)); }
@Test public void testMatch_Wildcard() throws IOException { expected.add(ScanQueryMatcher.MatchCode.DONE); long now = EnvironmentEdgeManager.currentTime(); UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan, new ScanInfo(this.conf, fam2, 0, 1, ttl, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, rowComparator, false),
@Test public void testMatchExplicitColumns() throws IOException { expected.add(ScanQueryMatcher.MatchCode.DONE); long now = EnvironmentEdgeManager.currentTime();
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testDelayingRunner() throws Exception{ MultiAction ma = new MultiAction(); ma.add(hri1.getRegionName(), new Action(new Put(DUMMY_BYTES_1), 0)); final AtomicLong endTime = new AtomicLong(); final long sleepTime = 1000; DelayingRunner runner = new DelayingRunner(sleepTime, ma.actions.entrySet().iterator().next()); runner.setRunner(new Runnable() { @Override public void run() { endTime.set(EnvironmentEdgeManager.currentTime()); } }); long startTime = EnvironmentEdgeManager.currentTime(); runner.run(); long delay = endTime.get() - startTime; assertTrue("DelayingRunner did not delay long enough", delay >= sleepTime); assertFalse("DelayingRunner delayed too long", delay > sleepTime + sleepTime*0.2); }
@Test public void testClientPoolRoundRobin() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); int poolSize = 3; int numVersions = poolSize * 2; Configuration conf = TEST_UTIL.getConfiguration(); conf.set(HConstants.HBASE_CLIENT_IPC_POOL_TYPE, "round-robin"); conf.setInt(HConstants.HBASE_CLIENT_IPC_POOL_SIZE, poolSize); Table table = TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, Integer.MAX_VALUE); final long ts = EnvironmentEdgeManager.currentTime(); Get get = new Get(ROW); get.addColumn(FAMILY, QUALIFIER); get.setMaxVersions(); for (int versions = 1; versions <= numVersions; versions++) { Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, ts + versions, VALUE); table.put(put); Result result = table.get(get); NavigableMap<Long, byte[]> navigableMap = result.getMap().get(FAMILY) .get(QUALIFIER); assertEquals("The number of versions of '" + Bytes.toString(FAMILY) + ":" + Bytes.toString(QUALIFIER) + " did not match", versions, navigableMap.size()); for (Map.Entry<Long, byte[]> entry : navigableMap.entrySet()) { assertTrue("The value at time " + entry.getKey() + " did not match what was put", Bytes.equals(VALUE, entry.getValue())); } } }
@Test public void testBusyRegionSplitPolicy() throws Exception { conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, policy = (BusyRegionSplitPolicy)RegionSplitPolicy.create(mockRegion, conf); long start = EnvironmentEdgeManager.currentTime(); Mockito.when(mockRegion.getBlockedRequestsCount()).thenReturn(10L); Mockito.when(mockRegion.getWriteRequestsCount()).thenReturn(20L); if (EnvironmentEdgeManager.currentTime() - start < 500) { assertFalse(policy.shouldSplit());
@Test public void testMergeFilterResponseCase2() throws Exception { List<MatchCode> expected = new ArrayList<>(); long now = EnvironmentEdgeManager.currentTime();
@Test public void testCanExecuteOfFixedIntervalRateLimiter() throws InterruptedException { RateLimiter limiter = new FixedIntervalRateLimiter(); // when set limit is 100 per sec, this FixedIntervalRateLimiter will support at max 100 per sec limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(50, testCanExecuteByRate(limiter, 50)); // refill the avail to limit limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(100, testCanExecuteByRate(limiter, 100)); // refill the avail to limit limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(100, testCanExecuteByRate(limiter, 200)); }
@Test public void testCanExecuteOfAverageIntervalRateLimiter() throws InterruptedException { RateLimiter limiter = new AverageIntervalRateLimiter(); // when set limit is 100 per sec, this AverageIntervalRateLimiter will support at max 200 per sec limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(50, testCanExecuteByRate(limiter, 50)); // refill the avail to limit limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(100, testCanExecuteByRate(limiter, 100)); // refill the avail to limit limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(200, testCanExecuteByRate(limiter, 200)); // refill the avail to limit limiter.set(100, TimeUnit.SECONDS); limiter.setNextRefillTime(EnvironmentEdgeManager.currentTime()); assertEquals(200, testCanExecuteByRate(limiter, 500)); }
@Test public void testMergeFilterResponseCase1() throws IOException { List<MatchCode> expected = new ArrayList<>(); long now = EnvironmentEdgeManager.currentTime();
@Test public void testCleanupFailoverQueues() throws Exception { Server server = new DummyServer("hostname1.example.org"); String file1 = group + "." + EnvironmentEdgeManager.currentTime() + ".log1"; String file2 = group + "." + EnvironmentEdgeManager.currentTime() + ".log2"; files.add(file1); files.add(file2);
@Test public void testMatch_ExpiredExplicit() throws IOException { ScanQueryMatcher.MatchCode.SEEK_NEXT_ROW, ScanQueryMatcher.MatchCode.DONE }; long now = EnvironmentEdgeManager.currentTime(); UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan, new ScanInfo(this.conf, fam2, 0, 1, testTTL, KeepDeletedCells.FALSE,
@Test public void testMatch_ExpiredWildcard() throws IOException { ScanQueryMatcher.MatchCode.SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.DONE }; long now = EnvironmentEdgeManager.currentTime(); UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan,
/** * This is a cryptic test. It is checking that we don't include a fake cell, one that has a * timestamp of {@link HConstants#OLDEST_TIMESTAMP}. See HBASE-16074 for background. * @throws IOException */ @Test public void testNeverIncludeFakeCell() throws IOException { long now = EnvironmentEdgeManager.currentTime(); // Do with fam2 which has a col2 qualifier. UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan, new ScanInfo(this.conf, fam2, 10, 1, ttl, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, rowComparator, false), get.getFamilyMap().get(fam2), now - ttl, now, null); Cell kv = new KeyValue(row1, fam2, col2, 1, data); Cell cell = PrivateCellUtil.createLastOnRowCol(kv); qm.setToNewRow(kv); MatchCode code = qm.match(cell); assertFalse(code.compareTo(MatchCode.SEEK_NEXT_COL) != 0); }
@Test public void testReplicationInReplay() throws Exception { final TableName tableName = htable1.getName(); final byte[] value = Bytes.toBytes("v"); WALEdit edit = new WALEdit(true); long now = EnvironmentEdgeManager.currentTime(); edit.add(new KeyValue(rowName, famName, qualifier, now, value)); WALKeyImpl walKey = new WALKeyImpl(hri.getEncodedNameAsBytes(), tableName, now, mvcc, scopes);
@Test public void MutateRowsAndCheckPostKill() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf("test"); long now = EnvironmentEdgeManager.currentTime();