package alluxio.master.block;

import alluxio.AlluxioURI;
import alluxio.client.WriteType;
import alluxio.client.file.FileSystem;
import alluxio.client.file.FileSystemTestUtils;
import alluxio.client.file.URIStatus;
import alluxio.exception.BlockInfoException;
import alluxio.master.LocalAlluxioCluster;
import alluxio.master.MasterRegistry;
import alluxio.master.MasterTestUtils;
import alluxio.wire.WorkerNetAddress;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.ExecutorService;

import static org.junit.Assert.fail;

/**
 * Integration test for block master functionality.
 */
public class BlockMasterIntegrationTest {

  private ExecutorService mExecutorsForClient;
  private LocalAlluxioCluster mCluster;

  @Before
  public void before() throws Exception {
    mCluster = new LocalAlluxioCluster();
    mCluster.initConfiguration();
    mCluster.start();
  }

  @Test
  public void journalBlockDeletion() throws Exception {
    FileSystem fs = mCluster.getClient();
    BlockMaster blockMaster = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class);
    AlluxioURI file = new AlluxioURI("/test");
    FileSystemTestUtils.createByteFile(fs, file, WriteType.MUST_CACHE, 10);
    URIStatus status = fs.getStatus(file);
    Long blockId = status.getBlockIds().get(0);
    Assert.assertNotNull(blockMaster.getBlockInfo(blockId));
    fs.delete(file);
    WorkerNetAddress workerAddress = mCluster.getWorkerAddress();
    try {
      blockMaster.getBlockInfo(blockId);
      fail("Expected the block to be deleted");
    } catch (BlockInfoException e) {
      // expected
    }
    mCluster.stop();
    MasterRegistry registry = MasterTestUtils.createLeaderFileSystemMasterFromJournal();
    try {
      registry.get(BlockMaster.class).getBlockInfo(blockId);
      fail("Expected the block to be deleted after restart");
    } catch (BlockInfoException e) {
      // expected
    }
    registry.stop();
  }
}

@@ -24,16 +24,54 @@
 block;%0A%0A
+import static org.junit.Assert.fail;%0A%0A
 import a
@@ -89,16 +89,16 @@
 xioURI;%0A
-
 import a
@@ -450,16 +450,17 @@
 ddress;%0A
+%0A
 import o
@@ -575,46 +575,8 @@
 e;%0A%0A
-import static org.junit.Assert.fail;%0A%0A
 /**%0A
@@ -886,24 +886,24 @@
 guration();%0A
-
     mCluster
@@ -917,16 +917,726 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void journalBlockCreation() throws Exception %7B%0A    FileSystem fs = mCluster.getClient();%0A    BlockMaster blockMaster = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class);%0A    AlluxioURI file = new AlluxioURI(%22/test%22);%0A    FileSystemTestUtils.createByteFile(fs, file, WriteType.MUST_CACHE, 10);%0A    URIStatus status = fs.getStatus(file);%0A    Long blockId = status.getBlockIds().get(0);%0A    Assert.assertNotNull(blockMaster.getBlockInfo(blockId));%0A    mCluster.stop();%0A    MasterRegistry registry = MasterTestUtils.createLeaderFileSystemMasterFromJournal();%0A    Assert.assertNotNull(registry.get(BlockMaster.class).getBlockInfo(blockId));%0A    registry.stop();%0A  %7D%0A%0A
   @Test%0A

Add block creation test