Java Code Examples for org.mockito.internal.util.reflection.Whitebox#setInternalState()

The following examples show how to use org.mockito.internal.util.reflection.Whitebox#setInternalState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircuitBreakerImplTest.java    From fastbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void isEventACircuitBreakerFailure_returns_whatever_breakingEventStrategy_returns() {
    // given
    BreakingEventStrategy<String> falseDecider = theString -> false;
    Whitebox.setInternalState(cbSpy, "breakingEventStrategy", falseDecider);

    // expect
    assertThat(cbSpy.isEventACircuitBreakerFailure("foo")).isFalse();

    // and given
    BreakingEventStrategy<String> trueDecider = theString -> true;
    Whitebox.setInternalState(cbSpy, "breakingEventStrategy", trueDecider);

    // expect
    assertThat(cbSpy.isEventACircuitBreakerFailure("foo")).isTrue();
}
 
Example 2
Source File: SpanTest.java    From wingtips with Apache License 2.0 6 votes vote down vote up
@Test
public void equals_returns_false_and_hashCode_different_if_durationNanos_is_different() {
    // given
    Span fullSpan1 = createFilledOutSpan(true);
    Span fullSpan2 = createFilledOutSpan(true);
    List<Long> badDataList = Arrays.asList(fullSpan1.getDurationNanos() + 1, null);

    for (Long badData : badDataList) {
        Whitebox.setInternalState(fullSpan2, "durationNanos", badData);

        // expect
        assertThat(fullSpan1.equals(fullSpan2)).isFalse();
        assertThat(fullSpan2.equals(fullSpan1)).isFalse();
        assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode());
    }
}
 
Example 3
Source File: Jersey1ApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    when(mockRequest.getRequestURI()).thenReturn("/fake/path");
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getQueryString()).thenReturn("queryString");

    listenerList = new ApiExceptionHandlerListenerList(
        Jersey1BackstopperConfigHelper.defaultApiExceptionHandlerListeners(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    unhandledSpy = spy(new Jersey1UnhandledExceptionHandler(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    handlerSpy = spy(new Jersey1ApiExceptionHandler(
        testProjectApiErrors,
        listenerList,
        ApiExceptionHandlerUtils.DEFAULT_IMPL, unhandledSpy));
    Whitebox.setInternalState(handlerSpy, "request", mockRequest);
    Whitebox.setInternalState(handlerSpy, "response", mock(HttpServletResponse.class));
}
 
Example 4
Source File: JaxRsApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    when(mockRequest.getRequestURI()).thenReturn("/fake/path");
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getQueryString()).thenReturn("queryString");

    listenerList = new JaxRsApiExceptionHandlerListenerList(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL);

    unhandledSpy = spy(new JaxRsUnhandledExceptionHandler(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    handlerSpy = spy(new JaxRsApiExceptionHandler(
        testProjectApiErrors,
        listenerList,
        ApiExceptionHandlerUtils.DEFAULT_IMPL, unhandledSpy));
    Whitebox.setInternalState(handlerSpy, "request", mockRequest);
    Whitebox.setInternalState(handlerSpy, "response", mock(HttpServletResponse.class));
}
 
Example 5
Source File: WingtipsToZipkinLifecycleListenerTest.java    From wingtips with Apache License 2.0 6 votes vote down vote up
@Test
public void spanCompleted_logs_error_during_handling_if_time_since_lastSpanHandlingErrorLogTimeEpochMillis_is_greater_than_MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS() {
    // given
    Logger loggerMock = mock(Logger.class);
    Whitebox.setInternalState(listener, "zipkinConversionOrReportingErrorLogger", loggerMock);
    long lastLogTimeToSet = System.currentTimeMillis() - (MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS + 10);
    Whitebox.setInternalState(listener, "lastSpanHandlingErrorLogTimeEpochMillis", lastLogTimeToSet);
    doThrow(new RuntimeException("kaboom")).when(spanReporterMock).report(any(zipkin2.Span.class));

    // when
    long before = System.currentTimeMillis();
    listener.spanCompleted(spanMock);
    long after = System.currentTimeMillis();

    // then
    verify(loggerMock).warn(anyString(), anyLong(), anyString(), anyString());
    // Also verify that the lastSpanHandlingErrorLogTimeEpochMillis value got updated.
    assertThat((long)Whitebox.getInternalState(listener, "lastSpanHandlingErrorLogTimeEpochMillis")).isBetween(before, after);
}
 
Example 6
Source File: GraphqlClientDataSourceServletTest.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnbindGraphqlClient() {
    GraphqlClient mockClient = mock(GraphqlClient.class);
    Mockito.doReturn("my-identifier").when(mockClient).getIdentifier();

    Set<String> identifiers = new HashSet<>(Arrays.asList("my-identifier", "another-identifier"));
    Whitebox.setInternalState(servlet, "identifiers", identifiers);

    servlet.unbindGraphqlClient(mockClient, Collections.emptyMap());

    Assert.assertEquals(1, identifiers.size());
    Assert.assertTrue(identifiers.contains("another-identifier"));
}
 
Example 7
Source File: CircuitBreakerImplTest.java    From fastbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void executeAsyncCall_explodes_immediately_if_circuit_is_OPEN() {
    // given
    Supplier<CompletableFuture<String>> supplierMock = mock(Supplier.class);
    Whitebox.setInternalState(cbSpy, "currentState", State.OPEN);

    // when
    Throwable cbExplosion = catchThrowable(() -> cbSpy.executeAsyncCall(supplierMock));

    // then
    assertThat(cbExplosion)
        .isNotNull()
        .isInstanceOf(CircuitBreakerOpenException.class);
    verifyZeroInteractions(supplierMock);
}
 
Example 8
Source File: DeviceGovernorImplTest.java    From bluetooth-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsOnline() {
    int onlineTimeout = 20;
    governor.setOnlineTimeout(onlineTimeout);

    Whitebox.setInternalState(governor, "lastInteracted", Instant.now());
    assertTrue(governor.isOnline());

    Whitebox.setInternalState(governor, "lastInteracted", Instant.now().minusSeconds(onlineTimeout));
    assertFalse(governor.isOnline());
}
 
Example 9
Source File: CircuitBreakerImplTest.java    From fastbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void throwExceptionIfCircuitBreakerIsOpen_schedules_half_open_check_and_does_not_explode_if_circuit_is_half_open() {
    // given
    Whitebox.setInternalState(cbSpy, "currentState", State.OPEN);
    ((AtomicBoolean) Whitebox.getInternalState(cbSpy, "halfOpenAllowSingleCall")).set(true);

    // when
    Throwable cbExplosion = catchThrowable(cbSpy::throwExceptionIfCircuitBreakerIsOpen);

    // then
    assertThat(cbExplosion).isNull();
    verify(cbSpy).scheduleHalfOpenStateTimeout();
}
 
Example 10
Source File: CircuitBreakerImplTest.java    From fastbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void executeAsyncCall_cancels_timeout_check_if_future_completes_first() throws InterruptedException {
    // given
    long callTimeoutMillis = 100;
    long callExecutionTimeMillis = 50;
    Whitebox
        .setInternalState(cbSpy, "callTimeoutNanos", Optional.of(Duration.ofMillis(callTimeoutMillis).toNanos()));
    CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
        try {
            Thread.sleep(callExecutionTimeMillis);
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "foo";
    });
    ScheduledExecutorService schedulerMock = mock(ScheduledExecutorService.class);
    ScheduledFuture scheduledFutureMock = mock(ScheduledFuture.class);
    doReturn(scheduledFutureMock).when(schedulerMock)
                                 .schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));
    doReturn(false).when(scheduledFutureMock).isDone();
    Whitebox.setInternalState(cbSpy, "scheduler", schedulerMock);

    // when
    CompletableFuture<String> result = cbSpy.executeAsyncCall(() -> future);
    result.join();
    Thread.sleep(50); // have to give the cancellation logic time to run before checking

    // then
    verify(scheduledFutureMock).cancel(false);
}
 
Example 11
Source File: CircuitBreakerImplTest.java    From fastbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void executeBlockingCall_gives_precedence_to_CircuitBreakerTimeoutException_if_supplier_takes_longer_than_callTimeout_even_if_supplier_throws_exception() {
    // given
    long callTimeoutMillis = 50;
    long callExecutionTimeMillis = 100;
    Whitebox
        .setInternalState(cbSpy, "callTimeoutNanos", Optional.of(Duration.ofMillis(callTimeoutMillis).toNanos()));
    Callable<String> supplier = () -> {
        try {
            Thread.sleep(callExecutionTimeMillis);
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        throw new Exception("crunch");
    };

    // when
    long startTimeMillis = System.currentTimeMillis();
    Throwable cbExplosion = catchThrowable(() -> cbSpy.executeBlockingCall(supplier));
    long endTimeMillis = System.currentTimeMillis();

    // then
    assertThat(cbExplosion)
        .isNotNull()
        .isInstanceOf(CircuitBreakerTimeoutException.class);
    assertThat((endTimeMillis - startTimeMillis)).isGreaterThanOrEqualTo(callExecutionTimeMillis);
}
 
Example 12
Source File: GraphqlResourceProviderFactoryTest.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {

    factory = new GraphqlResourceProviderFactory();

    client = new GraphqlDataServiceImpl();
    MockGraphqlDataServiceConfiguration config = Mockito.spy(new MockGraphqlDataServiceConfiguration());
    Whitebox.setInternalState(client, "configuration", config);
    Mockito.when(config.identifier()).thenReturn("my-catalog");

    factory.bindGraphqlDataService(client, null);
}
 
Example 13
Source File: SpanTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Test
public void toString_should_use_cached_json() {
    // given
    Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
    String uuidString = UUID.randomUUID().toString();
    Whitebox.setInternalState(validSpan, "cachedJsonRepresentation", uuidString);

    // when
    String toStringResult = validSpan.toString();

    // then
    assertThat(toStringResult).isEqualTo(uuidString);
}
 
Example 14
Source File: SpanTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Test
public void equals_returns_false_and_hashCode_different_if_traceId_is_different() {
    // given
    Span fullSpan1 = createFilledOutSpan(true);
    Span fullSpan2 = createFilledOutSpan(true);
    Whitebox.setInternalState(fullSpan2, "traceId", fullSpan1.getTraceId() + "_nope");

    // expect
    assertThat(fullSpan1.equals(fullSpan2)).isFalse();
    assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode());
}
 
Example 15
Source File: DcosAuthImplTest.java    From marathon-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Test that an invalid JSON payload does not leak the content of the credentials to the error log.
 *
 * @throws Exception
 */
@Test
public void testSecretIsNotLeakedInException() throws Exception {
    final Secret secret        = PowerMockito.mock(Secret.class);
    final String credentialsId = "cred-id";
    // final payload
    final String secretText = "this is not a valid json{}";
    Whitebox.setInternalState(secret, "value", secretText);

    when(credentials.getSecret()).thenReturn(secret);
    when(credentials.getId()).thenReturn(credentialsId);
    when(secret.getPlainText()).thenReturn(secretText);

    final DcosAuthImpl dcosAuth = new DcosAuthImpl(credentials,
            options,
            ContentType.APPLICATION_JSON,
            builder,
            context);

    try {
        dcosAuth.createDcosLoginPayload();
        assertTrue("Invalid JSON", false);
    } catch (AuthenticationException ae) {
        assertFalse("Contains secret", ae.getMessage().contains(secretText));
        assertTrue("Does not have the credential id", ae.getMessage().contains(credentialsId));
    } catch (Exception e) {
        assertTrue("Wrong exception was thrown", false);
    }
}
 
Example 16
Source File: TestPendingInvalidateBlock.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Test whether we can delay the deletion of unknown blocks in DataNode's
 * first several block reports.
 */
@Test
public void testPendingDeleteUnknownBlocks() throws Exception {
  final int fileNum = 5; // 5 files
  final Path[] files = new Path[fileNum];
  final DataNodeProperties[] dnprops = new DataNodeProperties[REPLICATION];
  // create a group of files, each file contains 1 block
  for (int i = 0; i < fileNum; i++) {
    files[i] = new Path("/file" + i);
    DFSTestUtil.createFile(dfs, files[i], BLOCKSIZE, REPLICATION, i);
  }
  // wait until all DataNodes have replicas
  waitForReplication();
  for (int i = REPLICATION - 1; i >= 0; i--) {
    dnprops[i] = cluster.stopDataNode(i);
  }
  Thread.sleep(2000);
  // delete 2 files, we still have 3 files remaining so that we can cover
  // every DN storage
  for (int i = 0; i < 2; i++) {
    dfs.delete(files[i], true);
  }

  // restart NameNode
  cluster.restartNameNode(false);
  InvalidateBlocks invalidateBlocks = (InvalidateBlocks) Whitebox
      .getInternalState(cluster.getNamesystem().getBlockManager(),
          "invalidateBlocks");
  InvalidateBlocks mockIb = Mockito.spy(invalidateBlocks);
  Mockito.doReturn(1L).when(mockIb).getInvalidationDelay();
  Whitebox.setInternalState(cluster.getNamesystem().getBlockManager(),
      "invalidateBlocks", mockIb);

  Assert.assertEquals(0L, cluster.getNamesystem().getPendingDeletionBlocks());
  // restart DataNodes
  for (int i = 0; i < REPLICATION; i++) {
    cluster.restartDataNode(dnprops[i], true);
  }
  cluster.waitActive();

  for (int i = 0; i < REPLICATION; i++) {
    DataNodeTestUtils.triggerBlockReport(cluster.getDataNodes().get(i));
  }
  Thread.sleep(2000);
  // make sure we have received block reports by checking the total block #
  Assert.assertEquals(3, cluster.getNamesystem().getBlocksTotal());
  Assert.assertEquals(4, cluster.getNamesystem().getPendingDeletionBlocks());

  cluster.restartNameNode(true);
  Thread.sleep(6000);
  Assert.assertEquals(3, cluster.getNamesystem().getBlocksTotal());
  Assert.assertEquals(0, cluster.getNamesystem().getPendingDeletionBlocks());
}
 
Example 17
Source File: DFSTestUtil.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public static void setEditLogForTesting(FSNamesystem fsn, FSEditLog newLog) {
  Whitebox.setInternalState(fsn.getFSImage(), "editLog", newLog);
  Whitebox.setInternalState(fsn.getFSDirectory(), "editLog", newLog);
}
 
Example 18
Source File: TestWebHDFSForHA.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure the WebHdfsFileSystem will retry based on RetriableException when
 * rpcServer is null in NamenodeWebHdfsMethods while NameNode starts up.
 */
@Test (timeout=120000)
public void testRetryWhileNNStartup() throws Exception {
  final Configuration conf = DFSTestUtil.newHAConfiguration(LOGICAL_NAME);
  MiniDFSCluster cluster = null;
  final Map<String, Boolean> resultMap = new HashMap<String, Boolean>();

  try {
    cluster = new MiniDFSCluster.Builder(conf).nnTopology(topo)
        .numDataNodes(0).build();
    HATestUtil.setFailoverConfigurations(cluster, conf, LOGICAL_NAME);
    cluster.waitActive();
    cluster.transitionToActive(0);

    final NameNode namenode = cluster.getNameNode(0);
    final NamenodeProtocols rpcServer = namenode.getRpcServer();
    Whitebox.setInternalState(namenode, "rpcServer", null);

    new Thread() {
      @Override
      public void run() {
        boolean result = false;
        FileSystem fs = null;
        try {
          fs = FileSystem.get(WEBHDFS_URI, conf);
          final Path dir = new Path("/test");
          result = fs.mkdirs(dir);
        } catch (IOException e) {
          result = false;
        } finally {
          IOUtils.cleanup(null, fs);
        }
        synchronized (TestWebHDFSForHA.this) {
          resultMap.put("mkdirs", result);
          TestWebHDFSForHA.this.notifyAll();
        }
      }
    }.start();

    Thread.sleep(1000);
    Whitebox.setInternalState(namenode, "rpcServer", rpcServer);
    synchronized (this) {
      while (!resultMap.containsKey("mkdirs")) {
        this.wait();
      }
      Assert.assertTrue(resultMap.get("mkdirs"));
    }
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 19
Source File: TestRenameWithSnapshots.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Test rename while the rename operation will exceed the quota in the dst
 * tree.
 */
@Test
public void testRenameUndo_5() throws Exception {
  final Path test = new Path("/test");
  final Path dir1 = new Path(test, "dir1");
  final Path dir2 = new Path(test, "dir2");
  final Path subdir2 = new Path(dir2, "subdir2");
  hdfs.mkdirs(dir1);
  hdfs.mkdirs(subdir2);
  
  final Path foo = new Path(dir1, "foo");
  final Path bar = new Path(foo, "bar");
  DFSTestUtil.createFile(hdfs, bar, BLOCKSIZE, REPL, SEED);
  
  SnapshotTestHelper.createSnapshot(hdfs, dir1, "s1");
  SnapshotTestHelper.createSnapshot(hdfs, dir2, "s2");
  
  // set ns quota of dir2 to 4, so the current remaining is 2 (already has
  // dir2, and subdir2)
  hdfs.setQuota(dir2, 4, Long.MAX_VALUE - 1);
  
  final Path foo2 = new Path(subdir2, foo.getName());
  FSDirectory fsdir2 = Mockito.spy(fsdir);
  Mockito.doThrow(new NSQuotaExceededException("fake exception")).when(fsdir2)
      .addLastINode((INodesInPath) Mockito.anyObject(),
          (INode) Mockito.anyObject(), Mockito.anyBoolean());
  Whitebox.setInternalState(fsn, "dir", fsdir2);
  // rename /test/dir1/foo to /test/dir2/subdir2/foo. 
  // FSDirectory#verifyQuota4Rename will pass since the remaining quota is 2.
  // However, the rename operation will fail since we let addLastINode throw
  // NSQuotaExceededException
  boolean rename = hdfs.rename(foo, foo2);
  assertFalse(rename);
  
  // check the undo
  assertTrue(hdfs.exists(foo));
  assertTrue(hdfs.exists(bar));
  INodeDirectory dir1Node = fsdir2.getINode4Write(dir1.toString())
      .asDirectory();
  List<INode> childrenList = ReadOnlyList.Util.asList(dir1Node
      .getChildrenList(Snapshot.CURRENT_STATE_ID));
  assertEquals(1, childrenList.size());
  INode fooNode = childrenList.get(0);
  assertTrue(fooNode.asDirectory().isWithSnapshot());
  INode barNode = fsdir2.getINode4Write(bar.toString());
  assertTrue(barNode.getClass() == INodeFile.class);
  assertSame(fooNode, barNode.getParent());
  List<DirectoryDiff> diffList = dir1Node
      .getDiffs().asList();
  assertEquals(1, diffList.size());
  DirectoryDiff diff = diffList.get(0);
  assertTrue(diff.getChildrenDiff().getList(ListType.CREATED).isEmpty());
  assertTrue(diff.getChildrenDiff().getList(ListType.DELETED).isEmpty());
  
  // check dir2
  INodeDirectory dir2Node = fsdir2.getINode4Write(dir2.toString()).asDirectory();
  assertTrue(dir2Node.isSnapshottable());
  QuotaCounts counts = dir2Node.computeQuotaUsage(fsdir.getBlockStoragePolicySuite());
  assertEquals(2, counts.getNameSpace());
  assertEquals(0, counts.getStorageSpace());
  childrenList = ReadOnlyList.Util.asList(dir2Node.asDirectory()
      .getChildrenList(Snapshot.CURRENT_STATE_ID));
  assertEquals(1, childrenList.size());
  INode subdir2Node = childrenList.get(0);
  assertSame(dir2Node, subdir2Node.getParent());
  assertSame(subdir2Node, fsdir2.getINode4Write(subdir2.toString()));
  diffList = dir2Node.getDiffs().asList();
  assertEquals(1, diffList.size());
  diff = diffList.get(0);
  assertTrue(diff.getChildrenDiff().getList(ListType.CREATED).isEmpty());
  assertTrue(diff.getChildrenDiff().getList(ListType.DELETED).isEmpty());
}
 
Example 20
Source File: TestRenameWithSnapshots.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Test the rename undo when removing dst node fails
 */
@Test
public void testRenameUndo_6() throws Exception {
  final Path test = new Path("/test");
  final Path dir1 = new Path(test, "dir1");
  final Path dir2 = new Path(test, "dir2");
  final Path sub_dir2 = new Path(dir2, "subdir");
  final Path subsub_dir2 = new Path(sub_dir2, "subdir");
  hdfs.mkdirs(dir1);
  hdfs.mkdirs(subsub_dir2);
  
  final Path foo = new Path(dir1, "foo");
  hdfs.mkdirs(foo);
  
  SnapshotTestHelper.createSnapshot(hdfs, dir1, "s1");
  SnapshotTestHelper.createSnapshot(hdfs, dir2, "s2");
  
  // set ns quota of dir2 to 4, so the current remaining is 1 (already has
  // dir2, sub_dir2, and subsub_dir2)
  hdfs.setQuota(dir2, 4, Long.MAX_VALUE - 1);
  FSDirectory fsdir2 = Mockito.spy(fsdir);
  Mockito.doThrow(new RuntimeException("fake exception")).when(fsdir2)
      .removeLastINode((INodesInPath) Mockito.anyObject());
  Whitebox.setInternalState(fsn, "dir", fsdir2);
  // rename /test/dir1/foo to /test/dir2/sub_dir2/subsub_dir2. 
  // FSDirectory#verifyQuota4Rename will pass since foo only be counted 
  // as 1 in NS quota. However, the rename operation will fail when removing
  // subsub_dir2.
  try {
    hdfs.rename(foo, subsub_dir2, Rename.OVERWRITE);
    fail("Expect QuotaExceedException");
  } catch (Exception e) {
    String msg = "fake exception";
    GenericTestUtils.assertExceptionContains(msg, e);
  }
  
  // check the undo
  assertTrue(hdfs.exists(foo));
  INodeDirectory dir1Node = fsdir2.getINode4Write(dir1.toString())
      .asDirectory();
  List<INode> childrenList = ReadOnlyList.Util.asList(dir1Node
      .getChildrenList(Snapshot.CURRENT_STATE_ID));
  assertEquals(1, childrenList.size());
  INode fooNode = childrenList.get(0);
  assertTrue(fooNode.asDirectory().isWithSnapshot());
  assertSame(dir1Node, fooNode.getParent());
  List<DirectoryDiff> diffList = dir1Node
      .getDiffs().asList();
  assertEquals(1, diffList.size());
  DirectoryDiff diff = diffList.get(0);
  assertTrue(diff.getChildrenDiff().getList(ListType.CREATED).isEmpty());
  assertTrue(diff.getChildrenDiff().getList(ListType.DELETED).isEmpty());
  
  // check dir2
  INodeDirectory dir2Node = fsdir2.getINode4Write(dir2.toString()).asDirectory();
  assertTrue(dir2Node.isSnapshottable());
  QuotaCounts counts = dir2Node.computeQuotaUsage(fsdir.getBlockStoragePolicySuite());
  assertEquals(3, counts.getNameSpace());
  assertEquals(0, counts.getStorageSpace());
  childrenList = ReadOnlyList.Util.asList(dir2Node.asDirectory()
      .getChildrenList(Snapshot.CURRENT_STATE_ID));
  assertEquals(1, childrenList.size());
  INode subdir2Node = childrenList.get(0);
  assertSame(dir2Node, subdir2Node.getParent());
  assertSame(subdir2Node, fsdir2.getINode4Write(sub_dir2.toString()));
  INode subsubdir2Node = fsdir2.getINode4Write(subsub_dir2.toString());
  assertTrue(subsubdir2Node.getClass() == INodeDirectory.class);
  assertSame(subdir2Node, subsubdir2Node.getParent());
  
  diffList = (  dir2Node).getDiffs().asList();
  assertEquals(1, diffList.size());
  diff = diffList.get(0);
  assertTrue(diff.getChildrenDiff().getList(ListType.CREATED).isEmpty());
  assertTrue(diff.getChildrenDiff().getList(ListType.DELETED).isEmpty());
}