@@ -0,0 +1,3406 @@
+/*%0A * Copyright 2018 Apache Software Foundation.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage io.hops.transaction;%0A%0Aimport io.hops.exception.StorageException;%0Aimport io.hops.exception.TransientStorageException;%0Aimport io.hops.metadata.HdfsStorageFactory;%0Aimport io.hops.metadata.common.entity.Variable;%0Aimport io.hops.metadata.yarn.dal.util.YARNOperationType;%0Aimport io.hops.transaction.handler.HDFSOperationType;%0Aimport io.hops.transaction.handler.HopsTransactionalRequestHandler;%0Aimport io.hops.transaction.handler.LightWeightRequestHandler;%0Aimport io.hops.transaction.lock.LockFactory;%0Aimport io.hops.transaction.lock.TransactionLockTypes;%0Aimport io.hops.transaction.lock.TransactionLocks;%0Aimport java.io.IOException;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0Aimport org.apache.hadoop.conf.Configuration;%0Aimport org.apache.hadoop.hdfs.DFSConfigKeys;%0Aimport org.apache.hadoop.hdfs.HdfsConfiguration;%0Aimport org.apache.hadoop.hdfs.MiniDFSCluster;%0Aimport org.junit.After;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0Apublic class TestTransaction %7B%0A%0A  static MiniDFSCluster cluster;%0A%0A  @BeforeClass%0A  public static void setupCluster() throws Exception %7B%0A    Configuration conf = new HdfsConfiguration();%0A%0A    conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, %220.0.0.0:0%22);%0A    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_READ_KEY, true);%0A    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_WRITE_KEY, true);%0A    conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, 10);%0A%0A    cluster = new MiniDFSCluster.Builder(conf)%0A        .numDataNodes(0)%0A        .storagesPerDatanode(1)%0A        .build();%0A%0A    cluster.waitActive();%0A%0A  %7D%0A%0A  @After%0A  public void tearDown() %7B%0A    if (cluster != null) %7B%0A      cluster.shutdown();%0A    %7D%0A  %7D%0A%0A  @Test%0A  public void testDB() throws IOException %7B%0A    HdfsStorageFactory.formatStorage();%0A    new HopsTransactionalRequestHandler(%0A        HDFSOperationType.CHOOSE_UNDER_REPLICATED_BLKS) %7B%0A      @Override%0A      public void acquireLock(TransactionLocks locks) throws IOException %7B%0A        LockFactory lf = LockFactory.getInstance();%0A        locks.add(lf.getVariableLock(Variable.Finder.ReplicationIndex,%0A            TransactionLockTypes.LockType.WRITE));%0A      %7D%0A      final AtomicBoolean firstTime = new AtomicBoolean(true);%0A%0A      @Override%0A      public Object performTask() throws StorageException, IOException %7B%0A        LightWeightRequestHandler setRMDTMasterKeyHandler%0A            = new LightWeightRequestHandler(YARNOperationType.TEST) %7B%0A          @Override%0A          public Object performTask() throws IOException %7B%0A            if (firstTime.getAndSet(false)) %7B%0A              throw new TransientStorageException();%0A            %7D%0A            return null;%0A          %7D%0A        %7D;%0A        setRMDTMasterKeyHandler.handle();%0A        return null;%0A      %7D%0A    %7D.handle();%0A  %7D%0A%7D%0A

correct LightWeightRequestHandler to not rollback when called inside a TransactionalRequestHandler