Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.65 KB | None | 0 0
  1.     @Test
  2.     public void we_can_use_segments_in_sets_and_it_natively_does_equality_comparison() throws Exception {
  3.  
  4.         // the only things we care about ignoring on segments is eff/exp dates
  5.         Set<String> ignored_fields_when_dealing_with_equality = Sets.newHashSet();
  6.         List<org.apache.avro.Schema.Field> fields = Segment.SCHEMA$.getFields();
  7.         ignored_fields_when_dealing_with_equality.addAll(fields.stream().filter(field -> field.order() == org.apache.avro.Schema.Field.Order.IGNORE).map(org.apache.avro.Schema.Field::name).collect(Collectors.toList()));
  8.         assertThat(ignored_fields_when_dealing_with_equality).contains("expiration_date");
  9.         assertThat(ignored_fields_when_dealing_with_equality).contains("effective_date");
  10.         assertThat(ignored_fields_when_dealing_with_equality).contains("cid");
  11.         assertThat(ignored_fields_when_dealing_with_equality.size()).isEqualTo(3);
  12.  
  13.         Segment a = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").build();
  14.         Segment b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").build();
  15.  
  16.         assertThat(a).isEqualTo(b);
  17.  
  18.         b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").setEffectiveDate(20150101).build();
  19.         assertThat(a).isEqualTo(b);
  20.  
  21.         b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").setExpirationDate(20140101).setEffectiveDate(20150101).build();
  22.         assertThat(a).isEqualTo(b);
  23.  
  24.         b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").setExpirationDate(20140101).setEffectiveDate(20150101).build();
  25.         assertThat(a).isEqualTo(b);
  26.     }
  27.  
  28.     @Test
  29.     public void we_can_remove_a_segment() throws Exception {
  30.         long writes = ApplicationMetrics.Hbase.Profiles.Writes.getCount();
  31.         // segment we want to move
  32.         Segment segment = Segment.newBuilder()
  33.                 .setChannelType("web")
  34.                 .setEffectiveDate(20140101)
  35.                 .setExpirationDate(20150101)
  36.                 .setField("control")
  37.                 .setValue("true")
  38.                 .setSystemId("cameo")
  39.                 .setNetworkId("99")
  40.                 .setSiteId("5230001")
  41.                 .build();
  42.  
  43.         String row_key = HbaseProfileRepository.Schema.ConsumerKey(NEW_USER_ID);
  44.  
  45.         Consumer original_consumer = Consumer.newBuilder().setId(NEW_USER_ID).setSegments(Lists.newArrayList(segment)).build();
  46.         byte[] original_bytes = ConsumerSerializer.toBytes(original_consumer);
  47.  
  48.         Consumer modified_consumer_with_updated_segment = Consumer.newBuilder().setId(NEW_USER_ID).setSegments(new ArrayList<Segment>()).build();
  49.         byte[] modified_bytes = ConsumerSerializer.toBytes(modified_consumer_with_updated_segment);
  50.  
  51.  
  52.         when(client.get(eq(TABLE_NAME), eq(Schema.ConsumerKey(NEW_USER_ID)), eq(Schema.COLUMN_FAMILY), eq(Schema.Columns.Document), eq(1))).thenReturn(original_bytes);
  53.  
  54.         boolean success = profiles.tryRemoveSegment(NEW_USER_ID, segment.getField(), segment.getValue(), segment.getNetworkId(), segment.getSiteId());
  55.  
  56.         assertThat(success).isTrue();
  57.         verify(client, times(1)).checkAndPut(eq(TABLE_NAME), eq(row_key), eq(Schema.COLUMN_FAMILY), eq(Schema.Columns.Document), eq(modified_bytes), eq(original_bytes), eq(Durability.SKIP_WAL));
  58.         verify(profileQ, times(1)).publish(modified_consumer_with_updated_segment);
  59.         assertThat(ApplicationMetrics.Hbase.Profiles.Writes.getCount()).isEqualTo(writes + 1);
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement