// This file is part of OpenTSDB.
// Copyright (C) 2013 The OpenTSDB Authors.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.tools;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mock;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.opentsdb.core.Query;
import net.opentsdb.core.TSDB;
import net.opentsdb.core.Tags;
import net.opentsdb.core.BaseTsdbTest.FakeTaskTimer;
import net.opentsdb.meta.Annotation;
import net.opentsdb.storage.MockBase;
import net.opentsdb.uid.NoSuchUniqueId;
import net.opentsdb.uid.NoSuchUniqueName;
import net.opentsdb.uid.UniqueId;
import net.opentsdb.utils.Config;
import net.opentsdb.utils.Threads;
import org.hbase.async.Bytes;
import org.hbase.async.GetRequest;
import org.hbase.async.HBaseClient;
import org.hbase.async.KeyValue;
import org.hbase.async.PutRequest;
import org.hbase.async.Scanner;
import org.jboss.netty.util.HashedWheelTimer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.stumbleupon.async.Deferred;
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.management.*", "javax.xml.*",
"ch.qos.*", "org.slf4j.*",
"com.sum.*", "org.xml.*"})
@PrepareForTest({ TSDB.class, Config.class, UniqueId.class, HBaseClient.class,
GetRequest.class, PutRequest.class, KeyValue.class, Fsck.class,
FsckOptions.class, Scanner.class, Annotation.class, Tags.class,
HashedWheelTimer.class, Threads.class })
public class TestFsck {
protected byte[] GLOBAL_ROW =
new byte[] {0, 0, 0, 0x52, (byte)0xC3, 0x5A, (byte)0x80};
protected byte[] ROW = MockBase.stringToBytes("00000150E22700000001000001");
protected byte[] ROW2 = MockBase.stringToBytes("00000150E23510000001000001");
protected byte[] ROW3 = MockBase.stringToBytes("00000150E24320000001000001");
protected byte[] BAD_KEY = { 0x00, 0x00, 0x01 };
protected Config config;
protected TSDB tsdb = null;
protected HBaseClient client;
protected UniqueId metrics;
protected UniqueId tag_names;
protected UniqueId tag_values;
protected MockBase storage;
protected FsckOptions options;
protected FakeTaskTimer timer;
protected final static List<byte[]> tags = new ArrayList<byte[]>(1);
static {
tags.add(new byte[] { 0, 0, 1, 0, 0, 1});
}
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
client = mock(HBaseClient.class);
metrics = mock(UniqueId.class);
tag_names = mock(UniqueId.class);
tag_values = mock(UniqueId.class);
options = mock(FsckOptions.class);
timer = new FakeTaskTimer();
PowerMockito.mockStatic(Threads.class);
PowerMockito.when(Threads.newTimer(anyString())).thenReturn(timer);
PowerMockito.when(Threads.newTimer(anyInt(), anyString())).thenReturn(timer);
PowerMockito.whenNew(HashedWheelTimer.class).withNoArguments()
.thenReturn(timer);
PowerMockito.whenNew(HBaseClient.class).withAnyArguments()
.thenReturn(client);
config = new Config(false);
tsdb = new TSDB(client, config);
when(client.flush()).thenReturn(Deferred.fromResult(null));
storage = new MockBase(tsdb, client, true, true, true, true);
storage.setFamily("t".getBytes(MockBase.ASCII()));
when(options.fix()).thenReturn(false);
when(options.compact()).thenReturn(false);
when(options.resolveDupes()).thenReturn(false);
when(options.lastWriteWins()).thenReturn(false);
when(options.deleteOrphans()).thenReturn(false);
when(options.deleteUnknownColumns()).thenReturn(false);
when(options.deleteBadValues()).thenReturn(false);
when(options.deleteBadRows()).thenReturn(false);
when(options.deleteBadCompacts()).thenReturn(false);
when(options.threads()).thenReturn(1);
// replace the "real" field objects with mocks
Field met = tsdb.getClass().getDeclaredField("metrics");
met.setAccessible(true);
met.set(tsdb, metrics);
Field tagk = tsdb.getClass().getDeclaredField("tag_names");
tagk.setAccessible(true);
tagk.set(tsdb, tag_names);
Field tagv = tsdb.getClass().getDeclaredField("tag_values");
tagv.setAccessible(true);
tagv.set(tsdb, tag_values);
// mock UniqueId
when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
when(metrics.getNameAsync(new byte[] { 0, 0, 1 }))
.thenReturn(Deferred.fromResult("sys.cpu.user"));
when(metrics.getId("sys.cpu.system"))
.thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
when(metrics.getName(new byte[] { 0, 0, 2 })).thenReturn("sys.cpu.nice");
when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_names.getName(new byte[] { 0, 0, 1 })).thenReturn("host");
when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_names.getId("dc")).thenThrow(new NoSuchUniqueName("dc", "metric"));
when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_values.getName(new byte[] { 0, 0, 1 })).thenReturn("web01");
when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
when(tag_values.getName(new byte[] { 0, 0, 2 })).thenReturn("web02");
when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
when(tag_values.getId("web03"))
.thenThrow(new NoSuchUniqueName("web03", "metric"));
PowerMockito.mockStatic(Tags.class);
when(Tags.resolveIds((TSDB)any(), (ArrayList<byte[]>)any()))
.thenReturn(null); // don't care
when(metrics.width()).thenReturn((short)3);
when(tag_names.width()).thenReturn((short)3);
when(tag_values.width()).thenReturn((short)3);
}
@Test
public void globalAnnotation() throws Exception {
storage.addColumn(GLOBAL_ROW, new byte[] {1, 0, 0}, "{}".getBytes());
final Fsck fsck = new Fsck(tsdb, options);
fsck.runFullTable();
assertEquals(0, fsck.kvs_processed.get());
assertEquals(0, fsck.totalErrors());
}
@Test
public void noData() throws Exception {
final Fsck fsck = new Fsck(tsdb, options);
fsck.runFullTable();
assertEquals(0, fsck.kvs_processed.get());
assertEquals(0, fsck.totalErrors());
}
@Test
public void noErrors() throws Exception {
final byte[] qual1 = { 0x00, 0x07 };
final byte[] val1 = Bytes.fromLong(4L);
final byte[] qual2 = { 0x00, 0x27 };
final byte[] val2 = Bytes.fromLong(5L);
storage.addColumn(ROW, qual1, val1);
storage.addColumn(ROW, qual2, val2);
final Fsck fsck = new Fsck(tsdb, options);
fsck.runFullTable();
assertEquals(2, fsck.kvs_processed.get());
assertEquals(1, fsck.row
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
opentsdb.zip (567个子文件)
configure.ac 2KB
Makefile.am 37KB
AUTHORS 813B
mygnuplot.bat 55B
bootstrap 740B
check_tsd 12KB
check_tsd_v2 12KB
opentsdb.conf 3KB
opentsdb.conf 2KB
opentsdb.conf 2KB
conffiles 75B
control 391B
COPYING 34KB
Dockerfile 1KB
net.opentsdb.plugin.DummyPlugin 65B
.dir-locals.el 170B
.gitignore 538B
.gitignore 19B
.gitignore 15B
net.opentsdb.tsd.HttpRpcPlugin 36B
net.opentsdb.tsd.HttpSerializer 38B
favicon.ico 1KB
fat-jar-pom.xml.in 25KB
pom.xml.in 19KB
opentsdb.spec.in 4KB
tsdb.in 3KB
fetchdep.sh.in 1KB
TestFsck.java 157KB
TSDB.java 83KB
TestRollupSeq.java 81KB
TsdbQuery.java 74KB
TestCompactionQueue.java 70KB
UniqueId.java 68KB
MockBase.java 66KB
TestUniqueId.java 64KB
TestPutRpc.java 62KB
Fsck.java 60KB
TestHistogramDownsampler.java 60KB
TestTsdbQueryQueries.java 58KB
TestDownsampler.java 58KB
TestTreeRpc.java 54KB
QueryUi.java 53KB
TestUniqueIdRpc.java 49KB
MultiGetQuery.java 47KB
Tree.java 47KB
UidManager.java 45KB
HttpJsonSerializer.java 44KB
GraphHandler.java 44KB
TreeBuilder.java 43KB
TestFillingDownsampler.java 42KB
TestHttpQuery.java 42KB
Internal.java 41KB
TestQueryRpcLastDataPoint.java 41KB
TestQueryRpcLastDataPointWhenEnableAppends.java 41KB
TSMeta.java 41KB
TestMultiGetQuery.java 39KB
TestDateTime.java 39KB
TestUID.java 38KB
SaltScanner.java 38KB
TestExpressionIterator.java 38KB
TestTsdbQueryRollup.java 38KB
HttpSerializer.java 38KB
TestRollupRpc.java 38KB
QueryRpc.java 38KB
TestTSDBAddAggregatePoint.java 37KB
HttpQuery.java 37KB
TestUnionIterator.java 37KB
TestRollupUtils.java 36KB
BaseTsdbTest.java 36KB
TestTSUIDQuery.java 36KB
QueryExecutor.java 36KB
TestTags.java 35KB
CompactionQueue.java 34KB
TestRowSeq.java 34KB
PutDataPointRpc.java 34KB
OpenTSDBMain.java 34KB
QueryStats.java 33KB
Tags.java 32KB
TestTsdbQueryDownsample.java 32KB
AggregationIterator.java 32KB
TestInternal.java 31KB
TestQueryExecutor.java 31KB
TestQueryRpc.java 31KB
TestTsdbQueryAggregators.java 29KB
ConfigArgP.java 29KB
TSUIDQuery.java 28KB
Annotation.java 28KB
TestTree.java 28KB
Config.java 28KB
RpcManager.java 28KB
TestTsdbQuery.java 27KB
TreeRpc.java 27KB
TestTextImporter.java 27KB
TestIntersectionIterator.java 27KB
Branch.java 26KB
TestHistogramDataPointRpc.java 26KB
Aggregators.java 26KB
MetricForm.java 25KB
TestHttpJsonSerializer.java 25KB
TestConfigArgP.java 25KB
共 567 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
hello_中年人
- 粉丝: 7
- 资源: 324
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功