/** * @throws Exception If failed. */ @Test public void testOverrideNameMapperSimpleNameMapper() throws Exception { checkOverrideNameMapper(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @param nameMapper Name mapper. * @param idMapper ID mapper. * @return Mapper. */ private static BinaryInternalMapper resolveMapper(BinaryNameMapper nameMapper, BinaryIdMapper idMapper) { if ((nameMapper == null || (DFLT_MAPPER.nameMapper().equals(nameMapper))) && (idMapper == null || DFLT_MAPPER.idMapper().equals(idMapper))) return DFLT_MAPPER; if (nameMapper != null && nameMapper instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper)nameMapper).isSimpleName() && idMapper != null && idMapper instanceof BinaryBasicIdMapper && ((BinaryBasicIdMapper)idMapper).isLowerCase()) return SIMPLE_NAME_LOWER_CASE_MAPPER; if (nameMapper == null) nameMapper = DFLT_MAPPER.nameMapper(); if (idMapper == null) idMapper = DFLT_MAPPER.idMapper(); return new BinaryInternalMapper(nameMapper, idMapper, true); }
/** {@inheritDoc} */ @Override public String typeName(String clsName) { A.notNull(clsName, "clsName"); return isSimpleName ? simpleName(clsName) : clsName; }
/** * @throws Exception If failed. */ @Test public void testSimpleName() throws Exception { BinaryBasicNameMapper mapper = new BinaryBasicNameMapper(true); assertEquals("GridBinaryTestClass1", mapper.typeName(GridBinaryTestClass1.class.getName())); assertEquals("InnerClass", mapper.typeName(GridBinaryTestClass1.class.getName() + "$InnerClass")); }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsWithNonGlobalMapperJar() throws Exception { BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryIdMapper() { @Override public int typeId(String clsName) { if (clsName.endsWith("1")) return 300; else if (clsName.endsWith("2")) return 400; else return -500; } @Override public int fieldId(int typeId, String fieldName) { return 0; } }, Arrays.asList( new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), new BinaryTypeConfiguration("unknown.*") )); BinaryContext ctx = binaryContext(marsh); Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers"); assertEquals(3, typeMappers.size()); assertFalse(((BinaryBasicNameMapper)typeMappers.get(CLASS1_FULL_NAME).nameMapper()).isSimpleName()); assertEquals(300, typeMappers.get(CLASS1_FULL_NAME).idMapper().typeId(CLASS1_FULL_NAME)); assertFalse(((BinaryBasicNameMapper)typeMappers.get(CLASS2_FULL_NAME).nameMapper()).isSimpleName()); assertEquals(400, typeMappers.get(CLASS2_FULL_NAME).idMapper().typeId(CLASS2_FULL_NAME)); }
/** * @throws Exception If failed. */ @Test public void testClassNamesWithCustomMapperJar() throws Exception { BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryIdMapper() { @Override public int typeId(String clsName) { if (clsName.endsWith("1")) return 300; else if (clsName.endsWith("2")) return 400; else return -500; } @Override public int fieldId(int typeId, String fieldName) { return 0; } }, Arrays.asList( new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), new BinaryTypeConfiguration("unknown.*") )); BinaryContext ctx = binaryContext(marsh); Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers"); assertEquals(3, typeMappers.size()); assertFalse(((BinaryBasicNameMapper)typeMappers.get(CLASS1_FULL_NAME).nameMapper()).isSimpleName()); assertEquals(300, typeMappers.get(CLASS1_FULL_NAME).idMapper().typeId(CLASS1_FULL_NAME)); assertFalse(((BinaryBasicNameMapper)typeMappers.get(CLASS2_FULL_NAME).nameMapper()).isSimpleName()); assertEquals(400, typeMappers.get(CLASS2_FULL_NAME).idMapper().typeId(CLASS2_FULL_NAME)); }
/** * @throws Exception If failed. */ @Test public void testFullName() throws Exception { BinaryBasicNameMapper mapper = new BinaryBasicNameMapper(false); assertEquals(GridBinaryTestClass1.class.getName(), mapper.typeName(GridBinaryTestClass1.class.getName())); assertEquals(GridBinaryTestClass1.class.getName() + "$InnerClass", mapper.typeName(GridBinaryTestClass1.class.getName() + "$InnerClass")); } }
/** * @throws Exception If failed. */ @Test public void testClassNamesJarFullNameMapper() throws Exception { checkClassNamesJar(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsWithGlobalMapperJar() throws Exception { BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryIdMapper() { @Override public int typeId(String clsName) { if (clsName.endsWith("1")) return 300; else if (clsName.endsWith("2")) return 400; else return -500; } @Override public int fieldId(int typeId, String fieldName) { return 0; } }, Arrays.asList( new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), new BinaryTypeConfiguration("unknown.*") )); BinaryContext ctx = binaryContext(marsh); Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers"); assertEquals(3, typeMappers.size()); assertFalse(((BinaryBasicNameMapper)typeMappers.get(CLASS1_FULL_NAME).nameMapper()).isSimpleName()); assertEquals(300, typeMappers.get(CLASS1_FULL_NAME).idMapper().typeId(CLASS1_FULL_NAME)); assertFalse(((BinaryBasicNameMapper)typeMappers.get(CLASS2_FULL_NAME).nameMapper()).isSimpleName()); assertEquals(400, typeMappers.get(CLASS2_FULL_NAME).idMapper().typeId(CLASS2_FULL_NAME)); }
w.writeBoolean(bc.isCompactFooter()); w.writeBoolean(bc.getNameMapper() instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper)(bc.getNameMapper())).isSimpleName());
/** {@inheritDoc} */ @Override public String typeName(String clsName) { A.notNull(clsName, "clsName"); return isSimpleName ? simpleName(clsName) : clsName; }
/** * @throws Exception If failed. */ @Test public void testClassNamesJarSimpleNameMapper() throws Exception { checkClassNamesJar(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @param nameMapper Name mapper. * @param idMapper ID mapper. * @return Mapper. */ private static BinaryInternalMapper resolveMapper(BinaryNameMapper nameMapper, BinaryIdMapper idMapper) { if ((nameMapper == null || (DFLT_MAPPER.nameMapper().equals(nameMapper))) && (idMapper == null || DFLT_MAPPER.idMapper().equals(idMapper))) return DFLT_MAPPER; if (nameMapper != null && nameMapper instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper)nameMapper).isSimpleName() && idMapper != null && idMapper instanceof BinaryBasicIdMapper && ((BinaryBasicIdMapper)idMapper).isLowerCase()) return SIMPLE_NAME_LOWER_CASE_MAPPER; if (nameMapper == null) nameMapper = DFLT_MAPPER.nameMapper(); if (idMapper == null) idMapper = DFLT_MAPPER.idMapper(); return new BinaryInternalMapper(nameMapper, idMapper, true); }
/** * @throws Exception If failed. */ @Test public void testClassNamesFullNameMapper() throws Exception { checkClassNames(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
w.writeBoolean(bc.isCompactFooter()); w.writeBoolean(bc.getNameMapper() instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper)(bc.getNameMapper())).isSimpleName());
/** * @throws Exception If failed. */ @Test public void testClassNamesMixedMappers() throws Exception { checkClassNames(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsJarSimpleNameMapper() throws Exception { checkTypeConfigurationJar(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testOverrideJarFullNameMapper() throws Exception { checkOverrideJar(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsSimpleNameIdMapper() throws Exception { checkTypeConfigurations(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testOverrideIdMapperFullNameMapper() throws Exception { checkOverrideNameMapper(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }