@Override
 public boolean visitLabelTokenCommand(Command.LabelTokenCommand command) throws IOException {
   // id+in_use(byte)+type_blockId(int)+nr_type_records(int)
   int id = channel.getInt();
   byte inUseFlag = channel.get();
   boolean inUse = false;
   if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
     inUse = true;
   } else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
     throw new IOException("Illegal in use flag: " + inUseFlag);
   }
   LabelTokenRecord record = new LabelTokenRecord(id);
   record.setInUse(inUse);
   record.setNameId(channel.getInt());
   int nrTypeRecords = channel.getInt();
   for (int i = 0; i < nrTypeRecords; i++) {
     DynamicRecord dr = readDynamicRecord();
     if (dr == null) {
       return true;
     }
     record.addNameRecord(dr);
   }
   command.init(record);
   return false;
 }
예제 #2
0
 @Override
 public boolean visitLabelTokenCommand(Command.LabelTokenCommand command) throws IOException {
   LabelTokenRecord record = command.getRecord();
   // id+in_use(byte)+type_blockId(int)+nr_type_records(int)
   byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue();
   channel.put(NeoCommandType.LABEL_KEY_COMMAND);
   channel.putInt(record.getId()).put(inUse).putInt(record.getNameId());
   writeDynamicRecords(record.getNameRecords());
   return false;
 }
  @Test
  public void shouldReportEmptyName() throws Exception {
    // given
    LabelTokenRecord key = inUse(new LabelTokenRecord(42));
    DynamicRecord name = addLabelName(inUse(new DynamicRecord(6)));
    key.setNameId((int) name.getId());

    // when
    ConsistencyReport.LabelTokenConsistencyReport report = check(key);

    // then
    verify(report).emptyName(name);
    verifyNoMoreInteractions(report);
  }
  @Test
  public void shouldNotReportAnythingForConsistentlyChangedRecord() throws Exception {
    // given
    LabelTokenRecord oldRecord = notInUse(new LabelTokenRecord(42));
    LabelTokenRecord newRecord = inUse(new LabelTokenRecord(42));
    DynamicRecord name = addLabelName(inUse(new DynamicRecord(6)));
    name.setData(new byte[1]);
    newRecord.setNameId((int) name.getId());

    // when
    ConsistencyReport.LabelTokenConsistencyReport report = checkChange(oldRecord, newRecord);

    // then
    verifyNoMoreInteractions(report);
  }
  @Test
  public void shouldReportProblemsWithTheNewStateWhenCheckingChanges() throws Exception {
    // given
    LabelTokenRecord oldRecord = notInUse(new LabelTokenRecord(42));
    LabelTokenRecord newRecord = inUse(new LabelTokenRecord(42));
    DynamicRecord name = addLabelName(notInUse(new DynamicRecord(6)));
    newRecord.setNameId((int) name.getId());

    // when
    ConsistencyReport.LabelTokenConsistencyReport report = checkChange(oldRecord, newRecord);

    // then
    verify(report).nameBlockNotInUse(name);
    verifyNoMoreInteractions(report);
  }