2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.procedure
;
20 import static org
.junit
.Assert
.*;
22 import java
.io
.IOException
;
23 import java
.util
.Date
;
24 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
25 import org
.apache
.hadoop
.hbase
.master
.procedure
.ProcedureDescriber
;
26 import org
.apache
.hadoop
.hbase
.procedure2
.Procedure
;
27 import org
.apache
.hadoop
.hbase
.procedure2
.ProcedureStateSerializer
;
28 import org
.apache
.hadoop
.hbase
.procedure2
.ProcedureSuspendedException
;
29 import org
.apache
.hadoop
.hbase
.procedure2
.ProcedureYieldException
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
31 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
32 import org
.junit
.ClassRule
;
33 import org
.junit
.Test
;
34 import org
.junit
.experimental
.categories
.Category
;
36 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.ByteString
;
37 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.BytesValue
;
39 @Category({MasterTests
.class, SmallTests
.class})
40 public class TestProcedureDescriber
{
43 public static final HBaseClassTestRule CLASS_RULE
=
44 HBaseClassTestRule
.forClass(TestProcedureDescriber
.class);
46 public static class TestProcedure
extends Procedure
{
48 protected Procedure
[] execute(Object env
) throws ProcedureYieldException
,
49 ProcedureSuspendedException
, InterruptedException
{
54 protected void rollback(Object env
)
55 throws IOException
, InterruptedException
{
59 protected boolean abort(Object env
) {
64 protected void serializeStateData(ProcedureStateSerializer serializer
)
66 ByteString byteString
= ByteString
.copyFrom(new byte[] { 'A' });
67 BytesValue state
= BytesValue
.newBuilder().setValue(byteString
).build();
68 serializer
.serialize(state
);
72 protected void deserializeStateData(ProcedureStateSerializer serializer
)
79 TestProcedure procedure
= new TestProcedure();
80 String result
= ProcedureDescriber
.describe(procedure
);
82 Date epoch
= new Date(0);
84 assertEquals("{ ID => '-1', PARENT_ID => '-1', STATE => 'INITIALIZING', OWNER => '', "
85 + "TYPE => 'org.apache.hadoop.hbase.procedure.TestProcedureDescriber$TestProcedure', "
86 + "START_TIME => '" + epoch
+ "', LAST_UPDATE => '" + epoch
+ "', PARAMETERS => [ "
87 + "{ value => 'QQ==' } ] }", result
);