001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.procedure; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import java.io.IOException; 023import java.util.Date; 024import org.apache.hadoop.hbase.master.procedure.ProcedureDescriber; 025import org.apache.hadoop.hbase.procedure2.Procedure; 026import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; 027import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; 028import org.apache.hadoop.hbase.procedure2.ProcedureYieldException; 029import org.apache.hadoop.hbase.testclassification.MasterTests; 030import org.apache.hadoop.hbase.testclassification.SmallTests; 031import org.junit.jupiter.api.Tag; 032import org.junit.jupiter.api.Test; 033 034import org.apache.hbase.thirdparty.com.google.protobuf.ByteString; 035import org.apache.hbase.thirdparty.com.google.protobuf.BytesValue; 036 037@Tag(MasterTests.TAG) 038@Tag(SmallTests.TAG) 039public class TestProcedureDescriber { 040 041 public static class TestProcedure extends Procedure { 042 @Override 043 protected Procedure[] execute(Object env) 044 throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { 045 return null; 046 } 047 048 @Override 049 protected void rollback(Object env) throws IOException, InterruptedException { 050 } 051 052 @Override 053 protected boolean abort(Object env) { 054 return false; 055 } 056 057 @Override 058 protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { 059 ByteString byteString = ByteString.copyFrom(new byte[] { 'A' }); 060 BytesValue state = BytesValue.newBuilder().setValue(byteString).build(); 061 serializer.serialize(state); 062 } 063 064 @Override 065 protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { 066 } 067 } 068 069 @Test 070 public void test() { 071 TestProcedure procedure = new TestProcedure(); 072 String result = ProcedureDescriber.describe(procedure); 073 074 Date epoch = new Date(0); 075 076 assertEquals("{ ID => '-1', PARENT_ID => '-1', STATE => 'INITIALIZING', OWNER => '', " 077 + "TYPE => 'org.apache.hadoop.hbase.procedure.TestProcedureDescriber$TestProcedure', " 078 + "START_TIME => '" + epoch + "', LAST_UPDATE => '" + epoch + "', PARAMETERS => [ " 079 + "{ value => 'QQ==' } ] }", result); 080 } 081}