當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseReference.updateChildrenAsync方法代碼示例

本文整理匯總了Java中com.google.firebase.database.DatabaseReference.updateChildrenAsync方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseReference.updateChildrenAsync方法的具體用法?Java DatabaseReference.updateChildrenAsync怎麽用?Java DatabaseReference.updateChildrenAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.firebase.database.DatabaseReference的用法示例。


在下文中一共展示了DatabaseReference.updateChildrenAsync方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testUpdateRaisesCorrectRemoteEvents

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateRaisesCorrectRemoteEvents()
    throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  new WriteFuture(writer,
      new MapBuilder().put("a", 1).put("b", 2).put("c", 3).put("d", 4).build()).timedGet();

  EventHelper helper = new EventHelper().addValueExpectation(reader.child("a"))
      .addValueExpectation(reader.child("d"))
      .addChildExpectation(reader, Event.EventType.CHILD_CHANGED, "a")
      .addChildExpectation(reader, Event.EventType.CHILD_CHANGED, "d").addValueExpectation(reader)
      .startListening(true);

  writer.updateChildrenAsync(new MapBuilder().put("a", 4).put("d", 1).build());
  helper.waitForEvents();
  helper.cleanup();

  DataSnapshot snap = TestHelpers.getSnap(reader);
  Map<String, Object> expected = new MapBuilder().put("a", 4L).put("b", 2L).put("c", 3L)
      .put("d", 1L).build();
  Object result = snap.getValue();
  TestHelpers.assertDeepEquals(expected, result);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:27,代碼來源:DataTestIT.java

示例2: testUpdateRaisesChildEventsOnNewListener

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateRaisesChildEventsOnNewListener() throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
  EventHelper helper = new EventHelper().addValueExpectation(ref.child("a"))
      .addValueExpectation(ref.child("d"))
      .addChildExpectation(ref, Event.EventType.CHILD_ADDED, "a")
      .addChildExpectation(ref, Event.EventType.CHILD_ADDED, "d")
      .addValueExpectation(ref.child("c")).addValueExpectation(ref.child("d"))
      .addChildExpectation(ref, Event.EventType.CHILD_ADDED, "c")
      .addChildExpectation(ref, Event.EventType.CHILD_CHANGED, "d").startListening();

  ref.updateChildrenAsync(new MapBuilder().put("a", 11).put("d", 44).build());
  ref.updateChildrenAsync(new MapBuilder().put("c", 33).put("d", 45).build());
  helper.waitForEvents();
  helper.cleanup();
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:17,代碼來源:DataTestIT.java

示例3: testUpdateAfterSetLeafNodeWorks

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateAfterSetLeafNodeWorks() throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
  final Semaphore semaphore = new Semaphore(0);
  final Map<String, Object> expected = new MapBuilder().put("a", 1L).put("b", 2L).build();

  ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
      if (DeepEquals.deepEquals(snapshot.getValue(), expected)) {
        semaphore.release();
      }
    }

    @Override
    public void onCancelled(DatabaseError error) {
    }
  });
  ref.setValueAsync(42);
  ref.updateChildrenAsync(expected);

  TestHelpers.waitFor(semaphore);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:24,代碼來源:DataTestIT.java

示例4: testUpdateAffectPriorityLocally

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateAffectPriorityLocally()
    throws TestFailure, TimeoutException, InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  ReadFuture readFuture = ReadFuture.untilCountAfterNull(ref, 2);

  ref.setValueAsync(new MapBuilder().put("a", 1).put("b", 2).put("c", 3).build(), "testpri");
  ref.updateChildrenAsync(MapBuilder.of("a", 4));

  List<EventRecord> events = readFuture.timedGet();
  DataSnapshot snap = events.get(0).getSnapshot();
  assertEquals("testpri", snap.getPriority());

  snap = events.get(1).getSnapshot();
  assertEquals(4L, snap.child("a").getValue());
  assertEquals("testpri", snap.getPriority());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:19,代碼來源:DataTestIT.java

示例5: testChildAddedEvents

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testChildAddedEvents() throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  Map<String, Object> initial =
      new MapBuilder()
          .put("a", MapBuilder.of("value", 5L))
          .put("c", MapBuilder.of("value", 3L))
          .build();

  final List<String> snapshotNames = new ArrayList<>();
  final List<String> prevNames = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  final ChildEventListener testListener =
      ref.orderByChild("value")
          .addChildEventListener(
              new TestChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot snap, String prevName) {
                  snapshotNames.add(snap.getKey());
                  prevNames.add(prevName);
                  semaphore.release();
                }
              });

  ref.setValueAsync(initial);
  TestHelpers.waitFor(semaphore, 2);
  Assert.assertEquals(Arrays.asList("c", "a"), snapshotNames);
  Assert.assertEquals(Arrays.asList(null, "c"), prevNames);

  Map<String, Object> updates = new HashMap<>();
  updates.put("b", MapBuilder.of("value", 4));
  updates.put("d", MapBuilder.of("value", 2));
  ref.updateChildrenAsync(updates);

  TestHelpers.waitFor(semaphore, 2);
  Assert.assertEquals(Arrays.asList("c", "a", "d", "b"), snapshotNames);
  Assert.assertEquals(Arrays.asList(null, "c", null, "c"), prevNames);
  ref.removeEventListener(testListener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:41,代碼來源:OrderByTestIT.java

示例6: testDeletingEntireQueryWindow

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testDeletingEntireQueryWindow()
    throws InterruptedException, TestFailure, TimeoutException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  final ReadFuture readFuture = ReadFuture.untilCount(ref.limitToLast(2), 3);

  // wait for null event
  TestHelpers.waitForRoundtrip(ref);

  ref.setValueAsync(
      MapBuilder.of(
          "a", MapBuilder.of(".value", 1, ".priority", 1),
          "b", MapBuilder.of(".value", 2, ".priority", 2),
          "c", MapBuilder.of(".value", 3, ".priority", 3)));

  ref.updateChildrenAsync(new MapBuilder().put("b", null).put("c", null).build());
  List<EventRecord> events = readFuture.timedGet();
  DataSnapshot snap = events.get(1).getSnapshot();

  Map<String, Object> expected = MapBuilder.of("b", 2L, "c", 3L);
  Object result = snap.getValue();
  TestHelpers.assertDeepEquals(expected, result);

  // The original set is still outstanding (synchronous API), so we have a
  // full cache to re-window against
  snap = events.get(2).getSnapshot();
  result = snap.getValue();
  TestHelpers.assertDeepEquals(MapBuilder.of("a", 1L), result);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:31,代碼來源:QueryTestIT.java

示例7: testOutOfViewQueryOnAChild

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testOutOfViewQueryOnAChild()
    throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  final ReadFuture parentFuture = ReadFuture.untilCountAfterNull(ref.limitToLast(1), 2);

  final List<DataSnapshot> childSnaps = new ArrayList<>();
  ref.child("a").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
      childSnaps.add(snapshot);
    }

    @Override
    public void onCancelled(DatabaseError error) {
    }
  });

  new WriteFuture(ref, MapBuilder.of("a", 1, "b", 2)).timedGet();
  assertEquals(1L, childSnaps.get(0).getValue());
  ref.updateChildrenAsync(MapBuilder.of("c", 3));
  List<EventRecord> events = parentFuture.timedGet();
  DataSnapshot snap = events.get(0).getSnapshot();
  Object result = snap.getValue();

  Map<String, Object> expected = MapBuilder.of("b", 2L);
  TestHelpers.assertDeepEquals(expected, result);

  snap = events.get(1).getSnapshot();
  result = snap.getValue();

  expected = MapBuilder.of("c", 3L);
  TestHelpers.assertDeepEquals(expected, result);
  assertEquals(1, childSnaps.size());
  assertEquals(1L, childSnaps.get(0).getValue());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:38,代碼來源:QueryTestIT.java

示例8: testUpdateRaisesCorrectLocalEvents

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateRaisesCorrectLocalEvents()
    throws InterruptedException, TestFailure, TimeoutException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  final ReadFuture readFuture = ReadFuture.untilCountAfterNull(ref, 2);

  ref.setValueAsync(new MapBuilder().put("a", 1).put("b", 2).put("c", 3).put("d", 4).build());

  EventHelper helper = new EventHelper().addValueExpectation(ref.child("a"))
      .addValueExpectation(ref.child("d"))
      .addChildExpectation(ref, Event.EventType.CHILD_CHANGED, "a")
      .addChildExpectation(ref, Event.EventType.CHILD_CHANGED, "d").addValueExpectation(ref)
      .startListening(true);

  ref.updateChildrenAsync(new MapBuilder().put("a", 4).put("d", 1).build());
  helper.waitForEvents();
  List<EventRecord> events = readFuture.timedGet();
  helper.cleanup();

  Map<String, Object> expected = new MapBuilder().put("a", 4L).put("b", 2L).put("c", 3L)
      .put("d", 1L).build();
  Object result = events.get(events.size() - 1).getSnapshot().getValue();
  TestHelpers.assertDeepEquals(expected, result);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:26,代碼來源:DataTestIT.java

示例9: testUpdateFiresCorrectEventWhenDeletingChild

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateFiresCorrectEventWhenDeletingChild()
    throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  final ReadFuture writerFuture = ReadFuture.untilCountAfterNull(writer, 2);
  new WriteFuture(writer, new MapBuilder().put("a", 12).put("b", 6).build()).timedGet();
  final Semaphore semaphore = new Semaphore(0);
  final ReadFuture readerFuture = new ReadFuture(reader, new ReadFuture.CompletionCondition() {
    @Override
    public boolean isComplete(List<EventRecord> events) {
      if (events.size() == 1) {
        semaphore.release();
      }
      return events.size() == 2;
    }
  });

  TestHelpers.waitFor(semaphore);

  writer.updateChildrenAsync(MapBuilder.of("a", null));
  DataSnapshot snap = writerFuture.timedGet().get(1).getSnapshot();

  Map<String, Object> expected = MapBuilder.of("b", 6L);
  TestHelpers.assertDeepEquals(expected, snap.getValue());

  snap = readerFuture.timedGet().get(1).getSnapshot();

  TestHelpers.assertDeepEquals(expected, snap.getValue());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:33,代碼來源:DataTestIT.java

示例10: testUpdateFiresCorrectEventWhenAllChildrenAreDeleted

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateFiresCorrectEventWhenAllChildrenAreDeleted()
    throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  final ReadFuture writerFuture = ReadFuture.untilCountAfterNull(writer, 2);
  new WriteFuture(writer, MapBuilder.of("a", 12)).timedGet();
  final Semaphore semaphore = new Semaphore(0);
  final ReadFuture readerFuture = new ReadFuture(reader, new ReadFuture.CompletionCondition() {
    @Override
    public boolean isComplete(List<EventRecord> events) {
      if (events.size() == 1) {
        semaphore.release();
      }
      return events.size() == 2;
    }
  });

  TestHelpers.waitFor(semaphore);

  writer.updateChildrenAsync(MapBuilder.of("a", null));
  DataSnapshot snap = writerFuture.timedGet().get(1).getSnapshot();

  assertNull(snap.getValue());

  snap = readerFuture.timedGet().get(1).getSnapshot();

  assertNull(snap.getValue());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:32,代碼來源:DataTestIT.java

示例11: testUpdateFiresCorrectEventOnChangedChildren

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testUpdateFiresCorrectEventOnChangedChildren()
    throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  final ReadFuture writerFuture = ReadFuture.untilCountAfterNull(writer, 2);
  new WriteFuture(writer, MapBuilder.of("a", 12)).timedGet();
  final Semaphore semaphore = new Semaphore(0);
  final ReadFuture readerFuture = new ReadFuture(reader, new ReadFuture.CompletionCondition() {
    @Override
    public boolean isComplete(List<EventRecord> events) {
      if (events.size() == 1) {
        semaphore.release();
      }
      return events.size() == 2;
    }
  });

  TestHelpers.waitFor(semaphore);

  writer.updateChildrenAsync(MapBuilder.of("a", 11));
  DataSnapshot snap = writerFuture.timedGet().get(1).getSnapshot();

  Map<String, Object> expected = MapBuilder.of("a", 11L);
  TestHelpers.assertDeepEquals(expected, snap.getValue());

  snap = readerFuture.timedGet().get(1).getSnapshot();

  TestHelpers.assertDeepEquals(expected, snap.getValue());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:33,代碼來源:DataTestIT.java


注:本文中的com.google.firebase.database.DatabaseReference.updateChildrenAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。