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.procedure2.store.region;
019
020import static org.junit.Assert.assertEquals;
021
022import java.io.IOException;
023import org.apache.hadoop.hbase.procedure2.Procedure;
024import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
025import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.NoopProcedure;
026
027import org.apache.hbase.thirdparty.com.google.protobuf.Int64Value;
028
029import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState;
030
031public class RegionProcedureStoreTestProcedure extends NoopProcedure<Void> {
032  private static long SEQ_ID = 0;
033
034  public RegionProcedureStoreTestProcedure() {
035    setProcId(++SEQ_ID);
036  }
037
038  @Override
039  protected Procedure<Void>[] execute(Void env) {
040    return null;
041  }
042
043  @Override
044  protected void rollback(Void env) {
045  }
046
047  @Override
048  protected boolean abort(Void env) {
049    return false;
050  }
051
052  @Override
053  protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
054    long procId = getProcId();
055    if (procId % 2 == 0) {
056      Int64Value.Builder builder = Int64Value.newBuilder().setValue(procId);
057      serializer.serialize(builder.build());
058    }
059  }
060
061  @Override
062  protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException {
063    long procId = getProcId();
064    if (procId % 2 == 0) {
065      Int64Value value = serializer.deserialize(Int64Value.class);
066      assertEquals(procId, value.getValue());
067    }
068  }
069
070  public void setParent(Procedure<?> proc) {
071    super.setParentProcId(proc.getProcId());
072  }
073
074  public void finish() {
075    setState(ProcedureState.SUCCESS);
076  }
077}