Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void we_can_use_segments_in_sets_and_it_natively_does_equality_comparison() throws Exception {
- // the only things we care about ignoring on segments is eff/exp dates
- Set<String> ignored_fields_when_dealing_with_equality = Sets.newHashSet();
- List<org.apache.avro.Schema.Field> fields = Segment.SCHEMA$.getFields();
- 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()));
- assertThat(ignored_fields_when_dealing_with_equality).contains("expiration_date");
- assertThat(ignored_fields_when_dealing_with_equality).contains("effective_date");
- assertThat(ignored_fields_when_dealing_with_equality).contains("cid");
- assertThat(ignored_fields_when_dealing_with_equality.size()).isEqualTo(3);
- Segment a = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").build();
- Segment b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").build();
- assertThat(a).isEqualTo(b);
- b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").setEffectiveDate(20150101).build();
- assertThat(a).isEqualTo(b);
- b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").setExpirationDate(20140101).setEffectiveDate(20150101).build();
- assertThat(a).isEqualTo(b);
- b = Segment.newBuilder().setChannelType("web").setField("control").setValue("true").setNetworkId("99").setExpirationDate(20140101).setEffectiveDate(20150101).build();
- assertThat(a).isEqualTo(b);
- }
- @Test
- public void we_can_remove_a_segment() throws Exception {
- long writes = ApplicationMetrics.Hbase.Profiles.Writes.getCount();
- // segment we want to move
- Segment segment = Segment.newBuilder()
- .setChannelType("web")
- .setEffectiveDate(20140101)
- .setExpirationDate(20150101)
- .setField("control")
- .setValue("true")
- .setSystemId("cameo")
- .setNetworkId("99")
- .setSiteId("5230001")
- .build();
- String row_key = HbaseProfileRepository.Schema.ConsumerKey(NEW_USER_ID);
- Consumer original_consumer = Consumer.newBuilder().setId(NEW_USER_ID).setSegments(Lists.newArrayList(segment)).build();
- byte[] original_bytes = ConsumerSerializer.toBytes(original_consumer);
- Consumer modified_consumer_with_updated_segment = Consumer.newBuilder().setId(NEW_USER_ID).setSegments(new ArrayList<Segment>()).build();
- byte[] modified_bytes = ConsumerSerializer.toBytes(modified_consumer_with_updated_segment);
- 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);
- boolean success = profiles.tryRemoveSegment(NEW_USER_ID, segment.getField(), segment.getValue(), segment.getNetworkId(), segment.getSiteId());
- assertThat(success).isTrue();
- 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));
- verify(profileQ, times(1)).publish(modified_consumer_with_updated_segment);
- assertThat(ApplicationMetrics.Hbase.Profiles.Writes.getCount()).isEqualTo(writes + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement