Exemplo n.º 1
0
 @SuppressWarnings("EqualsBetweenInconvertibleTypes")
 @Test
 public void compareContainers() {
   Container container = account.getContainer("alpha");
   StoredObject object1 = container.getObject("img1.png");
   StoredObject object2 = container.getObject("img2.png");
   assertFalse(object1.equals("alpha"));
   assertFalse(object1.equals(object2));
   Map<StoredObject, String> containers = new TreeMap<StoredObject, String>();
   containers.put(object1, object1.getName());
   containers.put(object2, object2.getName());
   assertEquals(object1.getName(), containers.get(object1));
   assertEquals(object2.getName(), containers.get(object2));
   assertEquals(object1.getName().hashCode(), object1.hashCode());
 }
  @Test
  public void insertEventsFromMultipleStreams() {
    try {
      // save stream defn 1
      cassandraConnector.saveStreamDefinitionToStore(getCluster(), streamDefinition1);

      // save stream defn 3
      cassandraConnector.saveStreamDefinitionToStore(getCluster(), streamDefinition3);
    } catch (StreamDefinitionStoreException e) {
      e.printStackTrace();
      fail();
    }

    List<Event> eventList = new ArrayList<Event>();
    // retrieve stream id 1
    eventList.addAll(
        EventConverterUtils.convertFromJson(
            CassandraTestConstants.multipleProperEvent1, streamDefinition1.getStreamId()));

    // retrieve stream id 3
    eventList.addAll(
        EventConverterUtils.convertFromJson(
            CassandraTestConstants.multipleProperEvent3, streamDefinition3.getStreamId()));

    Map<String, Event> insertedEvents = new HashMap<String, Event>();
    int eventCounter = 0;
    for (Event event : eventList) {
      try {
        String rowKey = insertEvent(cluster, event, eventCounter++);
        // inserts row key only if event is valid, i.e. only proper events will add a row key
        insertedEvents.put(rowKey, event);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    assertEquals(4, insertedEvents.size());

    Map<String, Event> retrievedEvents = new HashMap<String, Event>();

    for (Map.Entry<String, Event> eventProps : insertedEvents.entrySet()) {
      try {
        retrievedEvents.put(
            eventProps.getKey(),
            getEvent(cluster, eventProps.getValue().getStreamId(), eventProps.getKey()));
      } catch (EventProcessingException e) {
        e.printStackTrace();
        fail();
      }
    }

    for (Map.Entry<String, Event> rowKeyAndEvent : retrievedEvents.entrySet()) {
      Event retrievedEvent = rowKeyAndEvent.getValue();
      Event originialEvent = insertedEvents.get(rowKeyAndEvent.getKey());
      System.out.println(
          "Retrieved Event : " + retrievedEvent + "\n Original Event : " + originialEvent + "\n\n");
      if (streamDefinition1.getStreamId().equals(originialEvent.getStreamId())) {
        assertTrue(DataBridgeUtils.equals(originialEvent, retrievedEvent, streamDefinition1));
      } else if (streamDefinition2.getStreamId().equals(originialEvent.getStreamId())) {
        assertTrue(DataBridgeUtils.equals(originialEvent, retrievedEvent, streamDefinition3));
      }
    }
  }