use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonManagedBinaryWriterTest method testFlushImmediatelyAfterIVM.
@Test
public void testFlushImmediatelyAfterIVM() throws Exception {
writer.flush();
writer.writeSymbol("burrito");
writer.finish();
IonReader reader = system().newReader(writer.getBytes());
reader.next();
assertEquals(reader.getSymbolTable().findSymbol("taco"), -1);
assertEquals(reader.getSymbolTable().findSymbol("burrito"), 15);
assertNull(reader.next());
IonDatagram dg = system().getLoader().load(writer.getBytes());
// Should be IVM SYMTAB burrito
assertEquals(3, dg.systemSize());
assertEquals("$ion_symbol_table", ((IonStruct) dg.systemGet(1)).getTypeAnnotations()[0]);
assertEquals("burrito", ((IonSymbol) dg.systemGet(2)).stringValue());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class SymbolTableTest method testLocalTableWithMissingImport.
@Test
public void testLocalTableWithMissingImport() throws IOException {
// Use a big symtab to get beyond any default allocation within the
// dummy symtab. This was done to trap a bug in LocalSymbolTable.
ArrayList<String> syms = new ArrayList<String>();
int maxId = 50;
for (int i = 1; i <= maxId; i++) {
syms.add("S" + i);
}
SymbolTable table = system().newSharedSymbolTable("T", 1, syms.iterator());
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
catalog.putTable(table);
final int import1id = systemMaxId() + 1;
final int import2id = systemMaxId() + 2;
final int local1id = systemMaxId() + maxId + 1;
final int local2id = local1id + 1;
String text = LocalSymbolTablePrefix + "{" + " symbols:[ \"local1\", \"local2\" ]," + " imports:[{name:'''T''', version:1," + " max_id:" + maxId + "}]," + "}\n" + "local1 local2 S1 S2";
byte[] binary = encode(text);
// Remove the imported table before decoding the binary.
assertSame(table, catalog.removeTable("T", 1));
IonDatagram dg = loader().load(binary);
checkSymbol("local1", local1id, dg.get(0));
checkSymbol("local2", local2id, dg.get(1));
checkUnknownSymbol(import1id, dg.get(2));
checkUnknownSymbol(import2id, dg.get(3));
SymbolTable st = dg.get(3).getSymbolTable();
checkLocalTable(st);
checkUnknownSymbol("S1", import1id, st);
checkUnknownSymbol("S2", import2id, st);
assertEquals(local1id - 1, st.getImportedMaxId());
SymbolTable dummy = checkFirstImport("T", 1, new String[maxId], st);
assertTrue(dummy.isSubstitute());
checkUnknownSymbol("S1", import1id, dummy);
checkUnknownSymbol("S2", import2id, dummy);
SymbolTable[] importedTables = st.getImportedTables();
assertEquals(1, importedTables.length);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class SymbolTableTest method testDupLocalSymbolOnDatagram.
@Test
public void testDupLocalSymbolOnDatagram() throws Exception {
final IonSystem ion1 = system();
final SymbolTable st = ion1.newSharedSymbolTable("foobar", 1, Arrays.asList("s1").iterator());
final IonMutableCatalog cat = new SimpleCatalog();
cat.putTable(st);
// amzn/ion-java/issues/46 has the datagram producing something like:
// $ion_1_0 $ion_symbol_table::{imports:[{name: "foobar", version: 1, max_id: 1}], symbols: ["s1", "l1"]} $11 $12
// local table should not have "s1", user values should be $10 $11
IonDatagram dg = ion1.newDatagram(st);
dg.add().newSymbol("s1");
dg.add().newSymbol("l1");
final IonSystem ion2 = newSystem(cat);
dg = ion2.getLoader().load(dg.getBytes());
checkSymbol("s1", 10, dg.get(0));
checkSymbol("l1", 11, dg.get(1));
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class SymbolTableTest method testLocalSymbolTableAppendImportBoundary.
@Test
public void testLocalSymbolTableAppendImportBoundary() throws IOException {
String text = LocalSymbolTablePrefix + "{" + " symbols:[ \"s11\"]" + "}\n" + "1\n" + LocalSymbolTablePrefix + "{" + " imports:" + ION_SYMBOL_TABLE + "," + " symbols:[ \"s21\"]" + "}\n" + "null";
IonDatagram datagram = loader().load(text);
SymbolTable symbolTable = datagram.get(0).getSymbolTable();
assertSame(symbolTable, datagram.get(1).getSymbolTable());
symbolTable.intern("o1");
symbolTable.intern("a1");
// new symbols don't influence SIDs for existing symbols; they are appended
checkSymbol("s11", systemMaxId() + 1, symbolTable);
checkSymbol("s21", systemMaxId() + 2, symbolTable);
checkSymbol("o1", systemMaxId() + 3, symbolTable);
checkSymbol("a1", systemMaxId() + 4, symbolTable);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = IonBinaryWriterBuilder.standard().build(out);
datagram.writeTo(writer);
writer.close();
IonDatagram roundtripped = loader().load(out.toByteArray());
assertTrue(Equivalence.ionEquals(datagram, roundtripped));
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class SymbolTableTest method testWriteWithSymbolTable.
@Test
public void testWriteWithSymbolTable() throws IOException {
// this example code is the fix for a previous defect
// which resulted in a bad assertion in
// IonWriterUser.close_local_symbol_table_copy
IonDatagram data;
data = system().newDatagram();
insert_local_symbol_table(data);
append_some_data(data);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = system().newTextWriter(out);
writer.writeValue(data);
writer.close();
// dataMap.put("value", out.toByteArray());
byte[] bytes = out.toByteArray();
assertNotNull(bytes);
}
Aggregations