当前位置: 首页>>代码示例>>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;未经允许,请勿转载。