Search in sources :

Example 1 with SimpleCatalog

use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.

the class SystemProcessingTestCase method testLocalTableWithGreaterImport.

/**
 * Import v2 but catalog has v3.
 */
@Test
public void testLocalTableWithGreaterImport() throws Exception {
    // expect 9 + 1 = 10
    final int fred1id_symtab = systemMaxId() + 1;
    final int fred2id_symtab = systemMaxId() + 2;
    final int fred3id_symtab = systemMaxId() + 3;
    final int local = systemMaxId() + Symtabs.FRED_MAX_IDS[2];
    // expect 9 + 4 + 1 = 14 id for local1
    final int local1id = local + 1;
    // 15: id for local2
    final int local2id = local + 2;
    // 16: id for fred_2, which has been removed from version 2 of the sym tab, so is now local
    final int local3id = local + 3;
    // 17: id for fred_5, which isn't present when version 2 was defined
    final int local4id = local + 4;
    SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
    Symtabs.register("fred", 2, catalog);
    SymbolTable fredV3 = Symtabs.register("fred", 3, catalog);
    // Make sure our syms don't overlap.
    assertTrue(fredV3.findSymbol("fred_5") != local3id);
    // version: 3: /* Removed fred_2 */
    // "{  name:"fred", version:3," +
    // "  symbols:["fred_1",null,"fred_3","fred_4","fred_5",]}"
    // fred_5 is not in table version 2, so it gets local symbol
    // fred_2 is missing from version 3
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:\"fred\", version:2, " + "            max_id:" + Symtabs.FRED_MAX_IDS[2] + "}]" + "} " + "local1 local2 fred_1 fred_2 fred_3 fred_5";
    // at this point the effective symbol list should be:
    // fred::version::'2'::symbols:[
    // 10::   '''fred_1''',
    // 11::        null, // removed when fred version 2 was removed and replaced by fred version 3 (which has the symbol fred_2 removed)
    // 12::   '''fred_3''',
    // 13::   '''fred_4''',
    // local::symbols:[
    // 14::   '''local1''',
    // 15::   '''local2''',
    // 16::   '''fred_2''', // since it's been removed from fred 3 (local 3)
    // 17::   '''fred_5''', // since it's below the max is of fred 2 so not visible (local 4)
    prepare(text);
    // Remove the imported table before decoding the binary.
    assertNotNull(catalog.removeTable("fred", 2));
    startIteration();
    nextValue();
    checkSymbol("local1");
    nextValue();
    checkSymbol("local2");
    nextValue();
    checkSymbol("fred_1", fred1id_symtab);
    nextValue();
    checkMissingSymbol("fred_2", fred2id_symtab);
    nextValue();
    checkSymbol("fred_3", fred3id_symtab);
    nextValue();
    checkSymbol("fred_5");
    checkEof();
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) SymbolTableTest(com.amazon.ion.impl.SymbolTableTest) Test(org.junit.Test)

Example 2 with SimpleCatalog

use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.

the class SystemProcessingTestCase method testSubstituteTableWithEqualVersionImport.

/**
 * Import v2 and catalog has v2.
 */
@Test
public void testSubstituteTableWithEqualVersionImport() throws Exception {
    SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
    Symtabs.register("fred", 2, catalog);
    checkImportTableSpecsWithVariants(catalog);
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) SymbolTableTest(com.amazon.ion.impl.SymbolTableTest) Test(org.junit.Test)

Example 3 with SimpleCatalog

use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.

the class BinaryWriterTest method testFlushingUnlockedSymtabWithImportsWithLSTAppend.

@Test
public void testFlushingUnlockedSymtabWithImportsWithLSTAppend() throws Exception {
    SimpleCatalog catalog = catalog();
    byte[] bytes = flushUnlockedSymtabWithImports(catalog, true);
    IonReader reader = IonReaderBuilder.standard().withCatalog(catalog).build(bytes);
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("fred_1", reader.stringValue());
    assertNull(reader.next());
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonReader(com.amazon.ion.IonReader) Test(org.junit.Test)

Example 4 with SimpleCatalog

use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.

the class SymbolTableTest method testImportWithBadMaxId.

@Test
public void testImportWithBadMaxId() {
    SymbolTable importedV1 = registerImportedV1();
    testImportWithBadMaxId(importedV1, "null.int");
    testImportWithBadMaxId(importedV1, "null");
    testImportWithBadMaxId(importedV1, "not_an_int");
    // testImportWithBadMaxId(importedV1, "0");  Zero isn't bad, its zero!
    testImportWithBadMaxId(importedV1, "-1");
    testImportWithBadMaxId(importedV1, "-2223");
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:\"imported\", version:1}]," + "}\n" + "null";
    IonValue v = oneValue(text);
    assertSame(importedV1, v.getSymbolTable().getImportedTables()[0]);
    SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
    catalog.removeTable(importedV1.getName(), importedV1.getVersion());
    badValue(text);
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 5 with SimpleCatalog

use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.

the class SymbolTableTest method testMutateDomAfterLocalSymbolTableAppend.

@Test
public void testMutateDomAfterLocalSymbolTableAppend() throws IOException {
    String text = LocalSymbolTablePrefix + "{" + "   imports:[{name:\"foo\", version:1, max_id:1}], " + "   symbols:[\"s1\", \"s2\"]" + "}\n" + // Symbol with unknown text from "foo"
    "$10\n" + // s1
    "$11\n" + LocalSymbolTablePrefix + "{" + "   imports:" + ION_SYMBOL_TABLE + "," + "   symbols:[\"s3\"]" + "}\n" + // s2
    "$12";
    IonDatagram datagram = loader().load(text);
    datagram.add(1, system().newSymbol("abc"));
    // s3
    datagram.add(system().newSymbol(new SymbolTokenImpl(null, 13)));
    // Symbol with unknown text from "foo"
    datagram.add(system().newSymbol(new SymbolTokenImpl(null, 10)));
    ByteArrayOutputStream textOutput = new ByteArrayOutputStream();
    ByteArrayOutputStream binaryOutput = new ByteArrayOutputStream();
    List<String> fooSymbols = Collections.singletonList("bar");
    SymbolTable fooTable = system().newSharedSymbolTable("foo", 1, fooSymbols.iterator());
    IonWriter textWriter = IonTextWriterBuilder.standard().withImports(fooTable).build(textOutput);
    datagram.writeTo(textWriter);
    textWriter.close();
    IonWriter binaryWriter = IonBinaryWriterBuilder.standard().withImports(fooTable).build(binaryOutput);
    datagram.writeTo(binaryWriter);
    binaryWriter.close();
    SimpleCatalog catalog = new SimpleCatalog();
    catalog.putTable(fooTable);
    IonSystem system = IonSystemBuilder.standard().withCatalog(catalog).build();
    IonDatagram textRoundtrip = system.getLoader().load(textOutput.toByteArray());
    IonDatagram binaryRoundtrip = system.getLoader().load(binaryOutput.toByteArray());
    assertEquals(textRoundtrip, binaryRoundtrip);
    assertEquals("bar", ((IonSymbol) textRoundtrip.get(0)).stringValue());
    assertEquals("abc", ((IonSymbol) textRoundtrip.get(1)).stringValue());
    assertEquals("s1", ((IonSymbol) textRoundtrip.get(2)).stringValue());
    assertEquals("s2", ((IonSymbol) textRoundtrip.get(3)).stringValue());
    assertEquals("s3", ((IonSymbol) textRoundtrip.get(4)).stringValue());
    assertEquals("bar", ((IonSymbol) textRoundtrip.get(0)).stringValue());
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonSystem(com.amazon.ion.IonSystem) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

SimpleCatalog (com.amazon.ion.system.SimpleCatalog)25 Test (org.junit.Test)22 SymbolTable (com.amazon.ion.SymbolTable)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 IonDatagram (com.amazon.ion.IonDatagram)5 SymbolTableTest (com.amazon.ion.impl.SymbolTableTest)5 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)5 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)3 IonSystem (com.amazon.ion.IonSystem)2 IonWriter (com.amazon.ion.IonWriter)2 IonMutableCatalog (com.amazon.ion.IonMutableCatalog)1 IonReader (com.amazon.ion.IonReader)1 IonValue (com.amazon.ion.IonValue)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1